Guest User

Untitled

a guest
Feb 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // SMOOTH SCROLLING TO ANCHORS
  2.  
  3. $('a[href*="#"]')
  4. // Remove links that don't actually link to anything
  5. .not('[href="#"]')
  6. .click(function(event) {
  7. // On-page links
  8. if (
  9. location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') &&
  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
  21. }, 1000, function() {
  22. //<!-- Start Comment Callback after animation
  23. // Must change focus! /End Comment-->
  24. var $target = $(target);
  25. $target.focus();
  26. if ($target.is(":focus")) { // Checking if the target was focused
  27. return false;
  28. } else {
  29. $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
  30. $target.focus(); // Set focus again
  31. };
  32.  
  33. });
  34.  
  35. }
  36. }
  37. });
Add Comment
Please, Sign In to add comment