2014-09-30 88 views
0

我很抱歉提出錯誤的問題。然而,我發現了一篇文章,詢問我究竟想要弄清楚什麼。我在這裏找到這個帖子:https://stackoverflow.com/questions/20785188/jquery-scrollto-internal-external-pageJquery Scroll內部/外部頁面

使用下面的代碼,我想了解如何使用href =「index.php /#home」來處理內部和外部頁面。另一篇文章顯示了這個例子,http://vostrel.cz/so/9652944/page.html,但它不適用於內部頁面。

的Javascript:

(function($) { 
var jump=function(e) 
{ 
    if (e){e.preventDefault();var target = $(this).attr("href");} 
    else{var target = location.hash;} 

    $('html,body').animate({scrollTop: $(target).offset().top},1100,function(){location.hash = target;}); 
} 

$('html, body').hide(); 

$(document).ready(function() 
{ 
    $('a[href^=#]').bind("click", jump); 

    if (location.hash){ 
    setTimeout(function(){$('html, body').scrollTop(0).show();jump()},0); 
    } 
    else{$('html, body').show()} 
}); 

})(jQuery) 

回答

0
$('a[href="index.php#home"]').on("click", jump); 

如果它在你的站點的根目錄,你會這麼像:

$('a[href="/#home"]').on("click", jump); 
0
 $('a[href^=#], a[href^="index.php#"]').bind("click", jump); 

,如果你想這將是最簡單的辦法,以匹配其中的任何頁面或其他限制發佈他們,我會更新答案。