此代碼運行良好,但是當我在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