blob: 9e66e551931a798e45f3a8b6aab444b176dd4758 [file] [log] [blame]
Unknownd2db0f12019-01-10 14:22:00 -05001/**
2 * smooth-scroll.js 1.0.0
3 * Make your page scrolling smooth
4 * Requires JQuery - Does not work with JQuery slim
5 * Based on https://css-tricks.com/snippets/jquery/smooth-scrolling/
6 */
7
8(function() {
9
10 var duration = 500
11
12 $('a[href*="#"]')
13 // Remove links that don't actually link to anything
14 .not('[href="#"]')
15 .click(function(event) {
16 // On-page links
17 if (
18 location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
19 &&
20 location.hostname == this.hostname
21 ) {
22 // Figure out element to scroll to
23 var target = $(this.hash);
24 target = target.length ? target : $('[name=' + this.hash.slice(1) + ']')
25 // Does a scroll target exist?
26 if (target.length) {
27 // Only prevent default if animation is actually gonna happen
28 event.preventDefault()
29
30 $('html, body').animate({
31 scrollTop: target.offset().top
32 },
33 duration, function() {
34 // Callback after animation
35 // Must change focus!
36 var $target = $(target);
37 $target.focus();
38 if ($target.is(":focus")) { // Checking if the target was focused
39 return false;
40 } else {
41 $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
42 $target.focus(); // Set focus again
43 };
44 });
45 }
46 }
47 });
48
49})();