Advertisement
Guest User

Untitled

a guest
May 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. $('a[href*="#"]')
  2. // Remove links that don't actually link to anything
  3. .not('[href="#"]')
  4. .not('[href="#0"]')
  5. .click(function(event) {
  6. // On-page links
  7. if (
  8. location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
  9. &&
  10. location.hostname == this.hostname
  11. ) {
  12. // Figure out element to scroll to
  13. var target = $(this.hash);
  14. target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  15. // Does a scroll target exist?
  16. if (target.length) {
  17. // Only prevent default if animation is actually gonna happen
  18. event.preventDefault();
  19. $('html, body').animate({
  20. scrollTop: target.offset().top - 100
  21. }, 1000);
  22. }
  23. }
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement