问题
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