Scroll to the top of the page using JavaScript?
snippet in javascript

Scroll to the top of the page using JavaScript?

user7407

window.scrollTo(xCoord, yCoord);

Scroll to the top of the page using JavaScript?

user7900

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

Scroll to the top of the page using JavaScript?

user8824

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

Scroll to the top of the page using JavaScript?

user5837

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

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

Scroll to the top of the page using JavaScript?

user4191

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

Scroll to the top of the page using JavaScript?

user8337

$('html, body').animate({
    scrollTop: $("#elementID").offset().top
}, 2000);

Scroll to the top of the page using JavaScript?

user9639

(function smoothscroll(){
    var currentScroll = document.documentElement.scrollTop || document.body.scrollTop;
    if (currentScroll > 0) {
         window.requestAnimationFrame(smoothscroll);
         window.scrollTo (0,currentScroll - (currentScroll/5));
    }
})();

Scroll to the top of the page using JavaScript?

user3534

$('.showPeriodMsgPopup').click(function(){
    //window.scrollTo(0, 0);
    $('html').animate({scrollTop:0}, 'slow');//IE, FF
    $('body').animate({scrollTop:0}, 'slow');//chrome, don't know if Safari works
    $('.popupPeriod').fadeIn(1000, function(){
        setTimeout(function(){$('.popupPeriod').fadeOut(2000);}, 3000);
    });
});

Scroll to the top of the page using JavaScript?

user766

var scrollToTop = window.setInterval(function() {
    var pos = window.pageYOffset;
    if ( pos > 0 ) {
        window.scrollTo( 0, pos - 20 ); // how far to scroll on each step
    } else {
        window.clearInterval( scrollToTop );
    }
}, 16); // how fast to scroll (this equals roughly 60 fps)

Scroll to the top of the page using JavaScript?

user9378

document.location.href = "#top";

Scroll to the top of the page using JavaScript?

user3301

   window.scroll({
      top: 0,
      left: 0,
      behavior: 'smooth'
    });

Scroll to the top of the page using JavaScript?

user1087

$('html, body').scrollTop(0);//For scrolling to top

$("body").scrollTop($("body")[0].scrollHeight);//For scrolling to bottom

Scroll to the top of the page using JavaScript?

user3713

window.location = '#'

Scroll to the top of the page using JavaScript?

user6208

<script>
$(document).ready(function(){
    $("button").click(function(){
        ($('body').scrollTop(0));
    });
});
</script>

Scroll to the top of the page using JavaScript?

user3507

document.body.scrollTop = document.documentElement.scrollTop = 0;

Scroll to the top of the page using JavaScript?

user4300

<script>
    $(window).scrollTop(100);
</script>

Scroll to the top of the page using JavaScript?

user150

$('html, body').animate({
    scrollTop: $("div").offset().top
}, time);

Scroll to the top of the page using JavaScript?

user597

// Get The Id
var topPage = document.getElementById(`top-page`)

// On Click, Scroll to the Top of Page
topPage.onclick = () => window.scrollTo({ top: 0, behavior: 'smooth' })

// On scroll, Show/Hide the button
window.onscroll = () => {
  window.scrollY > 500
    ? (topPage.style.display = 'block')
    : (topPage.style.display = 'none')
}

// CSS
body {
    background-color: #111;
    height:5000px;
}


#top-page {
  width: 50px;
  position: fixed;
  right: 30px;
  bottom: 30px;
  cursor: pointer;
  color: white;
  display: none;
}
// HTML
<img id="top-page" src="https://svgshare.com/i/LW3.sv" alt="Top">

javascript go to top of page

user6738

window.scroll({top: 0, left: 0});
//Or with jQuery
$('html,body').scrollTop(0);
//with animation
$('html, body').animate({ scrollTop: 0 }, 'fast');

js scroll to top

user1894

window.scrollTo(x-coord, y-coord);