scroll to top of page on button click javascript code example
Example 1: javascript go to top of page
window.scroll({
top: 0,
left: 0,
behavior: 'smooth'
});
Example 2: javascript scroll to top onclick
window.scroll({
top: 0,
left: 0,
behavior: 'smooth'
});
window.scroll({top: 0, left: 0});
$('html,body').scrollTop(0);
$('html, body').animate({ scrollTop: 0 }, 'fast');
Example 3: scroll to top
$("#scroll_icon").click(function()
{
jQuery('html,body').animate({scrollTop:0},2000);
})
Example 4: simple button scrolling with this
$('#id a').on('click', function (e) {
var href = $(this).attr('href')
$('html, body').animate({
scrollTop: $(href).offset().top
}, '300')
e.preventDefault()
})
Example 5: javascript scroll to top onclick
window.scroll({top: 0, left: 0});
$('html,body').scrollTop(0);
$('html, body').animate({ scrollTop: 0 }, 'fast');