jQuery scrolltop - not working after first use

≯℡__Kan透↙ 提交于 2019-12-10 17:53:23

问题


i am using jQuery scrolltop function on this menu: http://goethesternfriseure.de/index.php

the issue is that the scroll function is only working at the first time. after a second click on a link, it scrolls to much to the bottom.

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

            e.preventDefault();
        });

does anyone know whats happening there?


回答1:


your scroll top is not functioning cause you have to add "px" :

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

            e.preventDefault();
        });


来源:https://stackoverflow.com/questions/26694822/jquery-scrolltop-not-working-after-first-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!