By click on a button, I want to go to the top of the page. but it should not scroll to the top (no animation), instead it should go immediately to the top (just like a new page load). Is this possible with jquery? Thank you very much!
Asked
Active
Viewed 5,706 times
2 Answers
5
window.scrollTo(x-coord, y-coord);

Seth McClaine
- 9,142
- 6
- 38
- 64
-
Hello! thank you very much! It works well, but it looks a little bit weird, I can still see that it is scrolling very fast to the top. – fala Apr 15 '15 at 23:06
-
This may be dependent on your browser. Modern browsers force certain interaction. – Seth McClaine Apr 15 '15 at 23:07
-
You could try using an `animate` and setting the time lapse to 0 – Seth McClaine Apr 15 '15 at 23:07
-
1I understand! Thank you! How exactly would the `animate` code look like? – fala Apr 15 '15 at 23:15
-
I tried this, but it is the same like with window.scroll `$("html, body").animate({ scrollTop: 0 }, 0);` . Can I make with jquery in the same time a white flash? – fala Apr 15 '15 at 23:30
-
I don't understand `Can I make with jquery in the same time a white flash?` – Seth McClaine Apr 15 '15 at 23:41
1
You do not need jQuery to achieve this. All you need is a simple anchor tag right after the body tag.
<a name="anchor"> </a>
And to navigate there you would use.
<a href="#anchor">This will send you to the anchor.</a>

Darkrum
- 1,325
- 1
- 10
- 27
-
-
It should not matter. I see you have #portraits as the href so you would use – Darkrum Apr 15 '15 at 23:15
-
-
-
-