forked from LiveCarta/LiveCartaWP
Changed source root directory
This commit is contained in:
53
html/wp-content/themes/lawcarta/assets/js/featuresScroll.js
Normal file
53
html/wp-content/themes/lawcarta/assets/js/featuresScroll.js
Normal file
@@ -0,0 +1,53 @@
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
|
||||
var elemToScroll;
|
||||
|
||||
function scrollToHash(){
|
||||
var feHeight = $(elemToScroll).offset().top;
|
||||
|
||||
if ($('header').length && $('header').is(":visible")) {
|
||||
feHeight = feHeight - $('header').outerHeight();
|
||||
}
|
||||
|
||||
$('html, body').scrollTop(feHeight);
|
||||
}
|
||||
|
||||
function closestByClass(el, clazz) {
|
||||
while (el.className !== clazz) {
|
||||
el = el.parentNode;
|
||||
if (!el) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
if (location.hash) {
|
||||
setTimeout(function() {
|
||||
window.scrollTo(0, 0);
|
||||
elemToScroll = location.hash;
|
||||
scrollToHash();
|
||||
}, 1);
|
||||
}
|
||||
|
||||
var links = document.querySelectorAll('.feature-links.inner .feature-link');
|
||||
if (links.length > 0){
|
||||
for (var i = 0; i< links.length; i++){
|
||||
links[i].addEventListener('click', function(e){
|
||||
e.preventDefault();
|
||||
var el = closestByClass(e.target, 'feature-link');
|
||||
elemToScroll = el.hash;
|
||||
scrollToHash();
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
|
||||
//we don't actually need this
|
||||
$('body').on('click', '.article-index li a', function(e){
|
||||
e.preventDefault();
|
||||
elemToScroll = e.target.hash;
|
||||
scrollToHash();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user