此代码运行良好,但是当我在4-5次之后上下滚动时,它会崩溃并且所有元素都消失。为什么会发生这种情况,我该如何解决?jQuery滚动淡入崩溃
$(window).on("load",function() {
$(window).scroll(function() {
var winheight = $(window).innerHeight();
$(".fade").each(function() {
/* Check the location of each desired element */
var objectBottom = $(this).offset().top + $(this).outerHeight();
var windowBottom = $(window).scrollTop() + $(window).innerHeight();
/* If the element is completely within bounds of the window, fade it in */
if (windowBottom > (objectBottom - (winheight*0.65))) { //object comes into view (scrolling down)
if ($(this).css("opacity")==0) {$(this).fadeTo(500,1);}
} else { //object goes out of view (scrolling up)
if ($(this).css("opacity")==1) {$(this).fadeTo(500,0);}
}
});
}); $(window).scroll(); //invoke scroll-handler on page-load
});
您是否在控制台中收到任何消息? –
嗨,没有零信息,谢谢。 –
你可以发布你的HTML和CSS?或者制作一个JSFiddle? – thejoin