Scroll to the top of the page using JavaScript?

javascript scroll to top of page
javascript scroll to top of page onclick
scroll to top button bootstrap
javascript scroll to top of div
scroll to top jquery codepen
back to top button javascript smooth scrolling
scroll to top javascript smooth
jquery scroll to top of div

How do I scroll to the top of the page using a JavaScript? It is desirable even if the scrollbar instantly jumps to the top. I'm not looking for a smooth scrolling.

Window scrollTo() Method, Definition and Usage. The scrollTo() method scrolls the document to the specified coordinates. Tip: Use the scrollBy() method to scroll a specified distance  Scroll to the top of the page using JavaScript/jQuery. A scrollable page can be scrolled to the top using 2 approaches: The scrollTo() method of the window Interface can be used to scroll to a specified location on the page. It accepts 2 parameters the x and y coordinate of the page to scroll to.

If you do want smooth scrolling, try something like this:

$("a[href='#top']").click(function() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  return false;
});

That will take any <a> tag whose href="#top" and make it smooth scroll to the top.

Scroll to the top of the page using JavaScript/jQuery, Scroll to the top of the page using JavaScript/jQuery. A scrollable page can be scrolled to the top using 2 approaches: Method 1: Using window.scrollTo() How to Scroll to the Top of the Page Using jQuery/JavaScript. Topic: JavaScript / jQuery Prev|Next. Answer: Use the scrollTop Property. You can use the jQuery animate() method in combination with the scrollTop property to scroll to the top of the web page smoothly with an animation. Let's try out the following example to understand how it basically works:

Try this to scroll on top

<script>
 $(document).ready(function(){
    $(window).scrollTop(0);
});
</script>

How to scroll to top of page with JavaScript/jQuery?, Wow, I'm 9 years late to this question. Here you go: Add this code to your onload. // This prevents the page from scrolling down to where it was previously. if  The script checks the height position on every page scroll and fades in the widget if it has reached the 100px limit while another event listener detects the button clicks and smoothly scrolls back to the top of the page. /*Scroll to top when arrow up clicked BEGIN*/ $ ( window ). scroll (function () { var height = $ ( window ).scrollTop

You don't need jQuery to do this. A standard HTML tag will suffice...

<div id="jump_to_me">
    blah blah blah
</div>

<a target="#jump_to_me">Click Here To Destroy The World!</a>

Need to scroll to the top of the page?, The scrolling behavior of that is determined by CSS as well, but if you aren't doing that, you can force the smoothness in JavaScript: window.scroll  This page demonstrates how to use the JavaScript scrollBy and setTimeout methods to make a web page scroll down automatically. Change the timeout value to alter the scrolling speed in milliseconds. The example function below (arbitrarily called pageScroll) shows how this can work: To being scrolling automatically when the page loads, add the

Better solution with smooth animation:

// this changes the scrolling behavior to "smooth"
window.scrollTo({ top: 0, behavior: 'smooth' });

Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo#Example

Scroll to the Top of Page CSS and JavaScript , Below is the effect, and you can notice it jumps to the page-top straight away without any smooth effect. window.scrollTo(0, 0) is a sure bet to scroll the window​  // When the user clicks on the button, scroll to the top of the document function topFunction() { document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera}

Simple Scroll Back to Top of the Page Button JavaScript, Improve your website's user experience with a very simple arrow which fades in when visitors start scrolling the page. The page smoothly  Required. The coordinate to scroll to, along the x-axis (horizontal), in pixels: ypos: Number: Required. The coordinate to scroll to, along the y-axis (vertical), in pixels

How to Scroll to the Top of the Page Using jQuery/JavaScript, You can use the jQuery animate() method in combination with the scrollTop property to scroll to the top of the web page smoothly with an animation. Let's try out  A boolean value that indicates the type of the align: true - the top of the element will be aligned to the top of the visible area of the scrollable ancestor. false - the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor. If omitted, it will scroll to the top of the element.

How to Scroll to the Top of the Page Using JavaScript, This property of the window interface scrolls to a particular set of coordinates in the document. It has two parameters: the x and y. x-coord - pixel along the  Scroll Automatically to the Bottom of the Page. Asked 7 years, 6 months ago. Active yesterday. Viewed 635k times. Consider I have a list of questions. When I click on the first question, it should automatically take me to the bottom of the page. For a matter of fact, I do know that this can be done using jQuery.

Comments
  • 2019, to avoid "This site appears to use a scroll-linked positioning effect. This may not work well with asynchronous panning" use my script stackoverflow.com/a/57641938/5781320
  • That was my point, if you don't need to animate smooth scrolling then you don't need to use jQuery.
  • Funny as jeff's comment is honestly for people who just want things to work cross browser 95% of the time should just use jQuery. This is coming from someone who has to write a lot of pure javascript right now because we can't afford the overhead of a library slowing down ad code :(
  • This answer has nothing to do with the question. It would be fine if the question was: What script and methods should I use to scroll to the top of the page? Correct answer is here: stackoverflow.com/questions/4147112/…
  • Working for me in Firefox 40 and Chrome 44 (to address Mikhail's comment)
  • Scroll to the bottom of the page window.scrollTo(0, document.body.scrollHeight);
  • +1. I was just wondering how to do something like this and google lead me here. QUestion though, where is "scrollTop" function in the docs? I just looked but couldn't find it.
  • scrollTop is not function, it is a property of the window element
  • This does not work correctly when using animate's complete callback, as it will run it twice.
  • "html" and "body" are both required for browser compatibility, i.e. Chrome v27 scrolls with just "body" and IE8 does not. IE8 scrolls with just "html" but Chrome v27 does not.
  • @jalchr Actually, window.pageYOffset would be the property of the window e̶l̶e̶m̶e̶n̶t̶ object.