[英]Related UL blocks by LI elements
我什至不知道如何表达这个问题...我有2个UL块,每个块有10个LI元素,它们总是具有相同数量的元素,即10、160、12等。浮动固定导航,右边的块具有内容,我怎么知道知道哪个元素在视图上,所以在左边的块中我添加了一个类作为当前对象
<div class="leftnav">
<ul class="navigation">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</div>
<ul>
<li>Content 1</li>
<li>Content 2</li>
<li>Content 3</li>
<li>Content 4</li>
<li>Content 5</li>
<li>Content 6</li>
</ul>
因此,当用户向下滚动内容2并显示导航li时,该类为当前类...当用户单击导航时,它将滚动到右侧的内容...有人知道如何执行此操作吗?
基于动态信息,并假设您不想或不想影响标记,怎么办...。
$(window).on('scroll', handleScroll);
function handleScroll (e) {
var currentLiIndex;
$('{second ul} li').each(function (i, e) {
// loop through all the second li's,
// find which is closest to top of the window but below the scroll
if ($(e).offset().top > scrollY) {
currentLiIndex = i;
return false;
}
});
// clear actives
$(".navigation li").removeClass('active');
// target the nav li based on the index of the top function
// and add active class
$(".navigation li")[currentLiIndex].addClass('active');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.