In wordpress when a comment is posted the page refreshes and scrolls to the comment, but what I need to do is that the jquery automatically animate the scroll to that comment. The problem is that when I take the hash from url and find the comment with that Id it shows it's location is 0 but it's not.
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
Try offset hash.offset( ).top;
to get the value relative to the document
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.