JQuery scroll to top Code Example

Last Updated On Wednesday 25th Aug 2021

scroll to top jquery

Code Example

  • scrolltop in javascript
  • top scroll
	var scrollTop = function (){
    'use strict';
    var scrollTop = jQuery("button.scroltop");
    scrollTop.on('click',function() {
        jQuery("html, body").animate({
            scrollTop: 0
        }, 1000);
        return false;
    })

    jQuery(window).on("scroll", function() {
        var scroll = jQuery(window).scrollTop();
        if (scroll > 900) {
            jQuery("button.scroltop").fadeIn(1000);
        } else {
            jQuery("button.scroltop").fadeOut(1000);
        }
    });

    /* page scroll top on click function end*/
}