Guest User

Untitled

a guest
Mar 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  5. <script>
  6. $(document).ready(function(){
  7. // Add smooth scrolling to all links
  8. $("a").on('click', function(event) {
  9.  
  10. // Make sure this.hash has a value before overriding default behavior
  11. if (this.hash !== "") {
  12. // Prevent default anchor click behavior
  13. event.preventDefault();
  14.  
  15. // Store hash
  16. var hash = this.hash;
  17.  
  18. // Using jQuery's animate() method to add smooth page scroll
  19. // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
  20. $('html, body').animate({
  21. scrollTop: $(hash).offset().top
  22. }, 800, function(){
  23.  
  24. // Add hash (#) to URL when done scrolling (default click behavior)
  25. window.location.hash = hash;
  26. });
  27. } // End if
  28. });
  29. });
  30. </script>
  31. <style>
  32. body, html, .main {
  33. height: 100%;
  34. }
  35.  
  36. section {
  37. min-height: 100%;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42.  
  43. <a href="#section2">Click Me to Smooth Scroll to Section 2 Below</a>
  44.  
  45. <div class="main">
  46. <section></section>
  47. </div>
  48.  
  49. <div class="main" id="section2">
  50. <section style="background-color:blue"></section>
  51. </div>
  52.  
  53. </body>
  54. </html>
Add Comment
Please, Sign In to add comment