back to top in jquery simple code..




Html code :

<a href="#" class="scrollToTop">^</a>



Css code :

.scrollToTop{
    width:40px;
    height:33px;
    padding:4px;
    text-align:center;
    color: #fff;
font-weight:bold;
font-size:20px !important;
    text-decoration: none;
    position:fixed;
bottom:1px; right:10px;
    display:none;
background:#000000;
border-radius:4px;
 
}
.scrollToTop:hover{
    text-decoration:none !important;
color:#FFFFFF !important;

}




js code

$(document).ready(function(){
    //Check to see if the window is top if not then display button
    $(window).scroll(function(){
        if ($(this).scrollTop() > 100) {
            $('.scrollToTop').fadeIn();
        } else {
            $('.scrollToTop').fadeOut();
        }
    });

    //Click event to scroll to top
    $('.scrollToTop').click(function(){
        $('html, body').animate({scrollTop : 0},800);
        return false;
    });

});

No comments:

Post a Comment