goTop Button

goTop Button

by aisinvon

HTML

<div id="top">Go to top</div>

CSS

body{height:1000px; position:relative;}

#top{position:fixed; right:0; bottom:0;}

JavaScript

$(function(){
    $("#top").hide();
   
    $(window).scroll(function(){
    var scrollTopValue = $(window).scrollTop();
   
    if(scrollTopValue>100){
        $("#top").fadeIn();
    }else{
        $("#top").fadeOut();
    }    
    })

    
    $("#top").click(function(){
        $("html, body").animate({scrollTop:0},600);
    })

})