Created
October 23, 2018 19:19
-
-
Save KustomDeveloper/ae7d40c03c28b30df49d2cef530194c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| //Smooth Scrolling Anchor Links | |
| var j = jQuery.noConflict(); | |
| j(function() { | |
| // Select all links with hashes | |
| j('a[href*="#"]') | |
| // Remove links that don't actually link to anything | |
| .not('[href="#"]') | |
| .not('[href="#0"]') | |
| .click(function(event) { | |
| // On-page links | |
| if ( | |
| location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') | |
| && | |
| location.hostname == this.hostname | |
| ) { | |
| // Figure out element to scroll to | |
| var target = j(this.hash); | |
| target = target.length ? target : j('[name=' + this.hash.slice(1) + ']'); | |
| // Does a scroll target exist? | |
| if (target.length) { | |
| // Only prevent default if animation is actually gonna happen | |
| event.preventDefault(); | |
| j('html, body').animate({ | |
| scrollTop: target.offset().top-100 | |
| }, 1000, function() { | |
| // Callback after animation | |
| // Must change focus! | |
| var jtarget = j(target); | |
| jtarget.focus(); | |
| if (jtarget.is(":focus")) { // Checking if the target was focused | |
| return false; | |
| } else { | |
| jtarget.attr('tabindex','-1'); // Adding tabindex for elements not focusable | |
| jtarget.focus(); // Set focus again | |
| }; | |
| }); | |
| } | |
| } | |
| }); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment