jQuery Smooth Scrolling on Page Load

后端 未结 5 1828
甜味超标
甜味超标 2021-01-02 16:24

I\'m using this jQuery Script to do Smooth Scrolling (Found on CSS-Tricks.com):

/** Smooth Scrolling Functionality **/
jQuery(document).ready(function($) {
          


        
5条回答
  •  心在旅途
    2021-01-02 16:59

    I found this to be the best way to do what I want so far:

    /** Smooth Scrolling Functionality **/
    var jump=function(e)
    {
        //alert('here');
       if (e){
           //e.preventDefault();
           var target = jQuery(this).attr("href").replace('/', '');
       }else{
           var target = location.hash;
       }
    
       jQuery('html,body').animate(
       {
           scrollTop: (jQuery(target).offset().top) - 100
       },500,function()
       {
           //location.hash = target;
       });
    
    }
    
    jQuery('html, body').hide();
    
    jQuery(document).ready(function($)
    {
        $(document).on('click', 'a[href*=#]', jump);
    
        if (location.hash){
            setTimeout(function(){
                $('html, body').scrollTop(0).show();
                jump();
            }, 0);
        }else{
            $('html, body').show();
        }
    });
    /** END SMOOTH SCROLLING FUNCTIONALITY **/
    

提交回复
热议问题