Guest User

Untitled

a guest
Oct 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. function handler(event) {
  2. var hash = event.target.hash;
  3. var headerHeight = $('header').height();
  4.  
  5. if (hash) {
  6. event.preventDefault();
  7.  
  8. var tag = $(hash);
  9.  
  10. if ($(hash).length) {
  11. var offset = tag.offset().top - headerHeight;
  12. $('html, body').stop().animate({scrollTop: offset},'slow');
  13. }
  14. }
  15. }
  16.  
  17. $('.main-nav a').on( "click", handler );
  18.  
  19. var myHash = location.hash; //получаем значение хеша
  20. location.hash = ''; //очищаем хеш
  21. if(myHash[1] != undefined){ //проверяем, есть ли в хеше какое-то значение
  22. $('html, body').animate({scrollTop: $(myHash).offset().top}, 500); //скроллим за полсекунды
  23. };
Add Comment
Please, Sign In to add comment