kisukedeath

Scroll animate jquery

Feb 1st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.50 KB | None | 0 0
  1. $('a[href^="#"]').on('click',function (e) {
  2.         e.preventDefault();
  3.  
  4.         var target = this.hash;
  5.         var $target = $(target);
  6.  
  7.         $('html, body').stop().animate({
  8.             'scrollTop': $target.offset().top
  9.         }, 900, 'swing', function () {
  10.             window.location.hash = target;
  11.         });
  12.     });
  13.  
  14. <a href="#services">Jump to services</a>
  15. <div id="services">
  16. </div>
  17.  
  18. Stop Anchor Being Included In URL
  19. $('html, body').stop().animate({
  20.      'scrollTop': $target.offset().top
  21. }, 900, 'swing');
Advertisement
Add Comment
Please, Sign In to add comment