Scroll to top with jQuery

Today I will tell you about scroll to top method.

Earlier it was very difficult and not very fancy like we had used Anchors, I hope you remember.

Anchors are used to enable links to a specific location on a page. Anchor links can be especially useful when navigating between sections of a long document, or when you want to link to a segment of a page instead of the top of the page.

But now days Top Scroll method are more successful. Please see how can we implement it

  <!doctype html>
    <meta charset="utf-8">
    <title>Scroll to top</title>
    <style type="text/css">
    #scroll-to-top {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 9999;
        display: none;
    <script src="" type="text/javascript" >
    <script type="text/javascript">
            if ($(this).scrollTop() > 50) {
            } else {
        $('#scroll-to-top a').click(function(){    
            $('body,html').animate({ scrollTop: 0 }, 600);
            return false;        
    <div style="height:1000px;">&nbsp;</div>
    <div id="scroll-to-top"><a href="#">Top</a></div>

You can view the demo on this page. See the link at right bottom.
You can use images for the top link for better user experience.

Scroll to top with jQuery Scroll to top with jQuery Reviewed by Altaf Hussain on 11:04 AM Rating: 5

No comments:

Altaf Web. Powered by Blogger.