Advertisement
Maria-I-Pap

Untitled

Oct 9th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  2. <script>
  3. $(document).ready(function(){
  4. // Add smooth scrolling to all links
  5. $("a").on('click', function(event) {
  6.  
  7. // Make sure this.hash has a value before overriding default behavior
  8. if (this.hash !== "") {
  9. // Prevent default anchor click behavior
  10. event.preventDefault();
  11.  
  12. // Store hash
  13. var hash = this.hash;
  14.  
  15. // Using jQuery's animate() method to add smooth page scroll
  16. // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
  17. $('html, body').animate({
  18. scrollTop: $(hash).offset().top
  19. }, 800, function(){
  20.  
  21. // Add hash (#) to URL when done scrolling (default click behavior)
  22. window.location.hash = hash;
  23. });
  24. } // End if
  25. });
  26. });
  27. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement