jQuery scrolltop - 第一次使用后不起作用

2024-01-09

我在此菜单上使用 jQuery 滚动顶部功能:http://goethesternfriseure.de/index.php http://goethesternfriseure.de/index.php

问题是滚动功能仅在第一次起作用。第二次点击链接后,它会滚动到底部。

$('.sectionlink').click(function(e){
            var sectionelement = $(this).attr("rel");
            var myoffset = $('#'+sectionelement).offset().top;
            $('html, body').animate({
                scrollTop: myoffset
            }, 800);

            e.preventDefault();
        });

有人知道那里发生了什么事吗?


您的滚动顶部无法正常工作,因为您必须添加“px”:

$('.sectionlink').click(function(e){
            var sectionelement = $(this).attr("rel");
            var myoffset = $('#'+sectionelement).offset().top;
            $('html, body').animate({
                scrollTop: myoffset+"px"
            }, 800);

            e.preventDefault();
        });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jQuery scrolltop - 第一次使用后不起作用 的相关文章

随机推荐