scroll up js code example
Example 1: javascript go to top of page
window.scroll({
top: 0,
left: 0,
behavior: 'smooth'
});
Example 2: scrool to top jquerry
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
Example 3: scroll down up js
var lastScrollTop = 0;
element.addEventListener("scroll", function(){
var st = window.pageYOffset || document.documentElement.scrollTop;
if (st > lastScrollTop){
} else {
}
lastScrollTop = st <= 0 ? 0 : st;
}, false);
Example 4: javascript scroll down
window.scrollTo(300, 500);
Example 5: scroll to top
$("#scroll_icon").click(function()
{
jQuery('html,body').animate({scrollTop:0},2000);
})
Example 6: 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()
})