Scroll to top

Scroll to top

WordPress
Amitpal Singh

1, Place the javascript code inside head tag:

<script type="text/javascript">
   $(document).ready(function(){ 
   
   $(window).scroll(function(){
    if ($(this).scrollTop() > 100) {
     $('.scrollup').fadeIn();
    } else {
     $('.scrollup').fadeOut();
    }
   }); 
   
   $('.scrollup').click(function(){
    $("html, body").animate({ scrollTop: 0 }, 600);
    return false;
   });
 
  });
</script>

2, Place the style code in css file:

.scrollup
{
position:fixed;
display:none;
right:50px;bottom:100px;
}

3, Place the html code in footer just above the closing of body tag i.e before

body

<div class="scrollup">image or text (scroll to top)</div>