gpt4 book ai didi

javascript - 滚动时事件菜单不会改变

转载 作者:行者123 更新时间:2023-11-28 02:43:36 25 4
gpt4 key购买 nike

我已经创建了一个右侧菜单,但是当我向下滚动时,它并没有将事件类更改为下一个菜单,我已经多次使用这段代码,但这次我没有得到结果,

  $(window).scroll(function() {
var scrollbarLocation = $(this).scrollTop();

scrollLink.each(function() {

var sectionOffset = $(this.hash).offset().top - 70;

if ( sectionOffset <= scrollbarLocation ) {
$('.icons').removeClass('iconactive');
$(this).children('.icons').addClass('iconactive');

}
});
});

DEMO

最佳答案

你需要定义scrollLink,你可以通过添加这样的函数在点击 anchor 链接时提供一些动画效果

 $(document).on('click', 'a[href^="#"]', function (event) {
event.preventDefault();
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top
}, 1000);
});

演示:http://jsfiddle.net/3xmop98u/

关于javascript - 滚动时事件菜单不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47035661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com