0
我有一個頁面分爲一個部分。除了一件事外,它完美的工作,腳本滾動頁面到特定的部分,但如果我會擊中多個鏈接,它會一次一個地將我發送到每個點擊鏈接。Javascript單頁滾動腳本滾動到每個點擊的鏈接一個接一個
jQuery(window).bind("load", function() {
var hash = window.location.hash;
hash = hash.replace("#", "");
var elem = jQuery(".pb-line-css-group-" + hash);
menu_scroll_to(elem);
});
jQuery(document).ready(function() {
jQuery(".menu-item A").click(function() {
var hash = jQuery(this).attr('href');
hash = hash.replace("#", "");
hash = hash.replace("/", "");
var elem = jQuery(".pb-line-css-group-" + hash);
menu_scroll_to(elem);
});
});
function menu_scroll_to(elem) {
if (elem) {
jQuery('html, body').animate({
scrollTop: elem.offset().top - 70
}, 2000, "easeOutQuint");
}
}
我想滾動到只有第一次點擊的鏈接,如果我將在滾動過程中再創鏈接不會滾動到這些位置
我建議你看看一些穩定的解決方案,如[fullPage.js](http://alvarotrigo.com/fullPage/)。當你開始考慮觸摸屏設備,觸摸筆記本電腦,動畫性能,跨瀏覽器兼容性,舊瀏覽器兼容性,回調,無限滾動,鍵盤可訪問性,響應能力等時,試圖重塑車輪只會讓你更加頭疼。 – Alvaro 2015-02-26 12:58:46