我使用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