0
我有一個簡單的jQuery點擊和scrollTO錨腳本。我有另一個頁面,其中我鏈接的內容爲index.php#home,index.php#約等...從另一頁面頁面動畫
如何從外部頁面實現scrollTo效果?我正在考慮將該部分鏈接爲index.php?page = home,並且在頁面加載時,取回home變量並應用動畫。
還有其他想法嗎?
編輯,我的代碼如下
$("nav a").click(function(event){
//prevent the default action for the click event
//event.preventDefault();
//get the full url - like mysitecom/index.htm#home
var full_url = this.href;
//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
var parts = full_url.split("#");
var trgt = parts[1];
//get the top offset of the target anchor
var target_offset = $("#"+trgt).offset();
var target_top = target_offset.top;
//goto that anchor by setting the body scroll top to anchor top
$('html, body').animate({scrollTop:target_top}, 500);
});