Monday 5 October 2015

Create 'Go To Top' or 'Scroll To Top' via jQuery


Create 'Go To Top' or 'Scroll To Top' via jQuery, please follow below steps:
1. Add the below HTML code,
< div class="scroll-to-top" >
     < a href="#" id="to-top" rel="nofollow" style="outline: none;" >Top< /a >
< /div >

2. Then, include the jQuery library and add the below Javascript Code
jQuery(function($) {

    var scrollToTop = function() {
        $("a[href='#top']").click(function () {
            $("html, body").animate({scrollTop: 0}, "slow");
            return false;
        });
    }
    // Call the scroll to top function.
    scrollToTop();

});


To check whether the Jquery Library is called or not

To check whether the Jquery Library is called or not, please run below function;

if (typeof jQuery != 'undefined') {
    alert("jQuery library is loaded!");
}else{
    alert("jQuery library is not found!");
}