我使用jQuery的scrollTop函数在不同的锚点之间切换时使我的滚动平滑。 首先,这里是urljQuery scrollTop - 移动结束时的动画扫描
这是我的jQuery脚本
“ZIEL”仅仅是“目标”的德语单词,只是为了让你知道为什么这个变量称为“ZIEL “
$(document).ready(function() {
$('a[href*=#]').bind("click", function(event) {
event.preventDefault();
var ziel = $(this).attr("href");
$('#portraitcontent').animate({
scrollTop: $(ziel).offset().top
}, 3000 , function(){location.hash = ziel;});
});
return false;
});
那么我该如何在动画结束时没有那么难看的跳动? 有什么想法?
我真的不知道该怎么做。花了几个小时与那个婊子!
感谢您的意见!
编辑
那么这个新代码:
$(document).ready(function() {
$('a[href*=#]').bind("click", function(event) {
event.preventDefault();
var ziel = $(this).attr("href");
$('#portrait-entry').animate({
scrollTop: $(ziel).offset().top - 230
}, 1500 , function(){
if(window.history.replaceState){
window.history.replaceState(null, document.title, ziel); // <--here
}
});
});
return false;
});
平滑滚动工作没有丑陋的跳跃 但现在 我anchorlinks不工作应该的样子。
请检查the problem - 当您点击“fortbildungen”,然后点击“mitgliedschaften”时,它不会滚动到锚点。 我想我必须做重置或s.th.就像那样,因为我认为当你在#anchor页面上时,这些链接不应该如何工作。
我没有进入js/jquery。所以也许有人可以给我一个建议。我不知道如何谷歌这种问题。
感谢您的帮助和编辑的代码,这使我的滚动流畅。
在动画的回调函数,你告诉窗口通过设置'的location.hash = ziel'来执行跳跃。 – Ohgodwhy