jQuery Smooth Scrolling on Page Load

后端 未结 5 1853
甜味超标
甜味超标 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 17:00

    These days you can scroll on page load with only javascript. I like to set a setTimeout just to give it some time before scrolling.

    if (window.location.hash) {
      var hash = window.location.hash;
      var element = document.querySelector(hash);
      
      if (element)
        element.scrollIntoView({
          behavior: "smooth",
          block: "nearest",
          inline: "start",
        });
    }
    

提交回复
热议问题