Phil
Phil

Reputation: 1453

Link to top of the page in HTML whilst not refreshing the page

I have made a site where at the bottom of the page there is a link which displays a div in the centre of the page using JQuery...

so when you click the link you stay on the same page, the entire page fades out however this div (which contains the terms of use for the business and website) fades in... I want this div to stay dead centre of the browser (which it curently does) but because the page is long enough for you to need to scroll the div is not centralised and you must then scroll up again to view it (because the said link is at the bottom in the footer), how would I create a link to the top of the page which will not refresh the said page!

Thanks for the help... I have tried to make sense but I feel I have slightly complicated simple question.

[=

Upvotes: 1

Views: 3236

Answers (4)

Mr Lister
Mr Lister

Reputation: 46569

You don't even need an anchor with a name (which is deprecated anyway). Just use

<a href="#">To top</a>

Upvotes: 4

dbrin
dbrin

Reputation: 15673

Use this $("body").scrollTop(0);

http://jsfiddle.net/dbrin/dcE94/embedded/result/

works a little better than anchors

Upvotes: 1

RTulley
RTulley

Reputation: 175

An internal HTML anchor link ala;

<a name="A"></a>

<a href="#A">Go to A</a>

Just place the first line at the top somewhere. Alternatively if the scrollbar is still there, it might look a bit off. You could always remove the content or disable it which should also remove the scroll bar. If the user clicks off or closes the div, the content could be re-loaded.

Upvotes: 1

D&#39;Arcy Rittich
D&#39;Arcy Rittich

Reputation: 171411

You can do this with anchor names.

See this JsFiddle example (scroll to the bottom and click the link):

http://jsfiddle.net/RahnR/2/

Upvotes: 4

Related Questions