当您在顶部滚动时,坚持类正在添加。如果你滚动很多小缩图出现在右边。所以有两个问题:
$(window).scroll(function() {
$('.text-layer').each(function(i) {
$window = $(window);
var increase = i * 50
var newHeight = $(".text-layer").outerHeight();
var newWidth = $(".text-layer").outerWidth();
var distance = $(this).parent().offset().top + newHeight
if ($window.scrollTop() >= distance) {
$(this).addClass('sticked').css("transform", "translate(100%," + increase + "px) scale(.8)");
$(this).parent().css({"height": newHeight, "width": newWidth });
checkit()
}
if ($window.scrollTop() <= distance) {
$(this).removeClass('sticked').css("transform", "translate(0px, 0px)");
}
});
});
function checkit() {
$('.text-layer.sticked').hover(function() {
$(this).toggleClass('test')
})
}