Guest User

Untitled

a guest
Jan 18th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. // Add smooth scrolling to all links
  2. $("a").on('click', function(event) {
  3.  
  4. // Make sure this.hash has a value before overriding default behavior
  5. if (this.hash !== "") {
  6. // Prevent default anchor click behavior
  7. event.preventDefault();
  8.  
  9. // Store hash
  10. var hash = this.hash;
  11.  
  12. // Using jQuery's animate() method to add smooth page scroll
  13. // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
  14. $('html, body').animate({
  15. scrollTop: $(hash).offset().top
  16. }, 800, function(){
  17.  
  18. // Add hash (#) to URL when done scrolling (default click behavior)
  19. window.location.hash = hash;
  20. });
  21. } // End if
  22. });
Add Comment
Please, Sign In to add comment