Saturday, 9 May 2015

JQuery Scroll to Top effect



HTML - 

<a href="#" title="Back to top">^Top</a>

JQuery -

jQuery(document).ready(function($){
        $(window).scroll(function(){
            if ($(this).scrollTop() < 200) {
                $('#smoothup') .fadeOut();
            } else {
                $('#smoothup') .fadeIn();
            }
        });
        $('#smoothup').on('click', function(){
            $('html, body').animate({scrollTop:0}, 'fast');
            return false;
            });
    });

 Complete -

<html>
<head>
<script>
jQuery(document).ready(function($){
        $(window).scroll(function(){
            if ($(this).scrollTop() < 200) {
                $('#smoothup') .fadeOut();
            } else {
                $('#smoothup') .fadeIn();
            }
        });
        $('#smoothup').on('click', function(){
            $('html, body').animate({scrollTop:0}, 'fast');
            return false;
            });
    });
<script>
</head>
<body>
    <a href="#" title="Back to top">^Top</a>
</body>
</html>

Share:

Blogger Tutorials

Blogger Templates

d-koder - Web Developer / Security Specialist / Penetration Tester I would like to write tutorials about the issue we use to get while coding something. Hope these small tuts will help developers worldwide. > Website

Interested In -

Html/Css
PHP
Javascript
Jquery
Ajax
JSON
GITHUB