I have a anchor tag that when you click on the "Up to the Top", it will move the web page to the top of the page. My anchor tag is #PAGETOP.
My question is, I am using the jQuery UI Dialog and basically would like to programmatically activate this #PAGETOP anchor so whenever the page always loads at startup, would like to ensure that the page moves immediately to the top of the page.
I would like to emulate the way stackoverflow moves to the top of all your questions when you paginate to the next page (if possible).
Tha开发者_Go百科nks.
To move to the 'PAGETOP' anchor in Javascript, use this:
location.hash = 'PAGETOP';
If you're wanting to do it on page load, in jQuery it'd be like this:
$(function() {
location.hash = 'PAGETOP';
});
Or take @Kip's idea and go pro with the scrollTo jQuery plugin. This plugin has additional options for different animations etc
<script>
$.scrollTo( "#PAGETOP", 1000 );
</script>
精彩评论