2016-06-10 127 views
0

在wordpress發表評論時,頁面刷新和滾動到評論,但我需要做的是,jquery自動爲該評論動畫滾動。問題是,當我從URL中獲取哈希值並通過該Id找到該評論時,它顯示它的位置是0,但它不是。WordPress的滾動評論

var hash, hash_s; 
if(window.location.hash) { 
    hash = $('#' + window.location.hash.substring(1)); 

    if(hash) { 
     hash_s = hash.position().top; 
     console.log(hash_s); 

     body.animate({ scrollTop: hash_s }, 600); 
    } 
} 

console.log(hash_s) outputs value 0 
+0

你有一個鏈接到網頁的價值? –

回答

1

嘗試offsethash.offset().top;獲得相對於文檔

+1

謝謝,我忘了這個:D –