jQuery scrolltop – 首次使用后无法正常工作
我在这个菜单上使用jQuery scrolltopfunction: http ://goethesternfriseure.de/index.php
问题是滚动function仅在第一次工作。 在第二次点击链接后,它会滚动到底部。
$('.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(); });