Keep URL unaffected when anchor link is clicked

前端 未结 5 2058
忘了有多久
忘了有多久 2021-02-04 12:26

I\'ve checked other posts on here, no results of what I\'m looking for. I want to click on

About
Conte
5条回答
  •  天命终不由人
    2021-02-04 12:53

    //dont use a, use class

     $(document).ready(function(){
     $(".mouse").on('click', function(event) {
    // Make sure this.hash has a value before overriding default behavior
      if (this.hash !== "") {
      // Prevent default anchor click behavior
      event.preventDefault();
     // Store hash
      var hash = this.hash;
     // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes 
     to scroll to the specified area
      $('html, body').animate({
        scrollTop: $("#section").offset().top
      }, 800, function(){
       // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = "";
      });
    } // End if  }); });
    

提交回复
热议问题