on button click scroll to top code example
Example 1: 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 2: scroll to top
$("#scroll_icon").click(function()
{
jQuery('html,body').animate({scrollTop:0},2000);
})
Example 3: 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 4: javascript scroll to top onclick
window.scroll({top: 0, left: 0});
$('html,body').scrollTop(0);
$('html, body').animate({ scrollTop: 0 }, 'fast');