javascript - window.location.replace vs scrollTop -
i running on chrome following snippets:
<a name="example"> </a>
the following code works correctly. goes #example expected.
window.location.replace('#example');
but following not work. go top of page -- not #example
.
var target = $('a[name="example"]'); var offset = target.offset(); var top = offset.top; console.log(top); $('html, body').animate({scrolltop:top}, 'slow');
the top
returns value 500+ something. missing? in advance help.
update:
after removing following css
position: fixed;
the above jquery code works!. need page "position: fixed;". how make above jquery code works "position: fixed;"?
have made sure document tall enough in order scroll position. this jsfiddle using own code , html made match seems work fine in chrome.
Comments
Post a Comment