Guest User

Untitled

a guest
Feb 21st, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function anchorScroll() {
  2.  
  3. $('a[href*="#"]')
  4. // Remove links that don't actually link to anything
  5. .not('[href="#"]')
  6. .not('[href="#0"]')
  7. .not('.ui-tabs-anchor')
  8.  
  9. .click(function(event) {
  10. // On-page links
  11. if (
  12. location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
  13. &&
  14. location.hostname == this.hostname
  15. ) {
  16. // Figure out element to scroll to
  17. var target = $(this.hash);
  18. target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  19.  
  20. // Does a scroll target exist?
  21. if (target.length) {
  22. // Only prevent default if animation is actually gonna happen
  23. event.preventDefault();
  24. $('html, body').animate({
  25. scrollTop: target.offset().top
  26. }, 1000, function() {
  27.  
  28. var $target = $(target);
  29. $target.focus();
  30.  
  31. if ($target.is(":focus")) { // Checking if the target was focused
  32. return false;
  33. } else {
  34. $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
  35. $target.focus(); // Set focus again
  36. };
  37. });
  38. }
  39. }
  40. });
  41. }
Add Comment
Please, Sign In to add comment