This repository has been archived by the owner on Mar 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from sul-dlss/make_learn_more_link_scroll_dow…
…n_the_homepage make learn more link scroll down the homepage
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
$(document).on('ready', function(){ | ||
if ($('body').hasClass('pages-show')) { | ||
// Select all links with hashes | ||
$('a[href*="#"]') | ||
// deselect 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 = $(this.hash); | ||
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); | ||
// Does a scroll target exist? | ||
if (target.length) { | ||
// Only prevent default if animation is actually gonna happen | ||
event.preventDefault(); | ||
$('html, body').animate({ | ||
scrollTop: target.offset().top | ||
}, 400, function() { | ||
// Callback after animation | ||
// Must change focus! | ||
var $target = $(target); | ||
$target.focus(); | ||
if ($target.is(":focus")) { // Checking if the target was focused | ||
return false; | ||
} else { | ||
$target.attr('tabindex','-1'); // Adding tabindex for elements not focusable | ||
$target.focus(); // Set focus again | ||
}; | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
}); |
This file contains 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