【发布时间】:2015-06-11 08:08:01
【问题描述】:
我想检测向下/向上滚动时屏幕上可见的元素。 我必须在针对该元素的菜单上设置为活动菜单项。
// must have a page class
$('.page').each(function(){
$positionData[$(this).attr('id')] = $(this).offset().top;
});
$(document).scroll(function(){
var $position = $(this).scrollTop();
if($position > $height && !$body.hasClass('scrolled')) {
$body.addClass('scrolled');
//detech the scroll is between an element offset
} else if($position < $height) {
$body.removeClass('scrolled');
}
});
有什么想法吗?
【问题讨论】:
标签: jquery html scroll position offset