rAthus

Smooth scroll vers ancre au clic et au chargement de la page

Jan 25th, 2021 (edited)
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* smooth scroll vers ancre au clic et au chargement de la page */
  2. $(document).on('click','[href*="#"]',function() {
  3.     var h = '#'+$(this).attr('href').split('#')[1];
  4.     if (h.indexOf('=')==-1 && $(h).length) {
  5.         $('html,body').stop(true).animate({scrollTop:$(h).offset().top-$('header').height()-50},500);
  6.         return false;
  7.     }
  8. });
  9. if (location.hash && $(location.hash).length) {
  10.     window.scrollTo(0,0);
  11.     $('html,body').stop(true).animate({scrollTop:$(location.hash).offset().top-$('header').height()-50},500);
  12.     history.pushState({},'',location.href.split('#')[0]);
  13.     return false;
  14. }
Add Comment
Please, Sign In to add comment