Scroll to Top using Jquery

Add a Simple Scroll to Top Link to your website using Jquery "scrollTop()" function

September 16, 2020

1) HTML Anchor Link (Place at the bottom before </body>)

<a id="a_scrolltoTop">&uarr;</a>

2) Jquery Code to Scroll to top of the page

$(function () {
    $(document).on("click"'#a_scrolltoTop'function () {
        $('html, body').animate({
            scrollTop: 0
        }, 800);
        return false;
    });
 
    $(window).on("scroll"function () {
        $(this).scrollTop() > 500 ? $("#a_scrolltoTop").fadeIn(50) : $("#a_scrolltoTop").fadeOut(500)
    });
});

3) CSS Style to make anchor visible at bottom to the right side.

#a_scrolltoTop {
    positionfixed;
    width40px;
    color#fff;
    line-height40px;
    background#324248;
    cursorpointer;
    displaynone;
    border-radius2px;
    bottom31px !important;
    right13px !important;
    padding-left15px;
}

Post Comments(0)

Leave a reply

Will not be displayed in comment box .

Loading...