我在我的页面中有一个列表(#js滚动),列表中的一些条目(li)有一个类'itemPage',我想要实现的是当用户滚动时,我想找到离滚动位置最近的'itemPage‘。
就像这样:
$(window).scrollTop().closest('.itemPage');优素福
发布于 2014-08-14 11:48:39
您需要遍历所有的lis,并将该位置与当前滚动位置进行比较。类似于:
var scrollTop = $(window).scrollTop();
$('li.itemPage').each(function() {
var top = $(this).position().top;
if (top > scrollTop) {
// This is the first li which is visible - do something with it
return false; // Stop the .each loop from continuing
}
});https://stackoverflow.com/questions/25307141
复制相似问题