可見這是我正在嘗試,但條件永遠不會觸發部分..類添加到一旦他們在視口中
$(window).scroll(function(e){
var scrollTop = $(window).scrollTop();
var viewportHeight = $(window).height();
$('section').each(function(){
var top = $(this).offset().top;
var bottom = top + $(this).height();
if(top <= scrollTop && bottom >= (scrollTop + vieportHeight)){
$(this).addClass('visible');
console.log('Hola');
}else{
console.log(top,bottom,scrollTop,viewportHeight);
}
});
});
小提琴:http://jsfiddle.net/rYeMC/
任何想法whyat我做錯誤?
http://remysharp.com/2009/01/26/element-in-view-event-plugin/一個很好的插件,它正在做你想做的事! – supersize
這裏有一個錯字和你的jsfiddle:vieportHeight –