Skip to content

Instantly share code, notes, and snippets.

@giventofly
Last active May 21, 2018 10:37
Show Gist options
  • Save giventofly/29d5de08cb8b874fca65349d30daed0b to your computer and use it in GitHub Desktop.
Save giventofly/29d5de08cb8b874fca65349d30daed0b to your computer and use it in GitHub Desktop.
scroll to
//scroll FAQ
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('.meta-about-content-left[data-section=faq]').addEventListener('click', function (e) {
e.preventDefault();
//get id to jump
const itemlink = $(e.target);
if (itemlink.is("a")) {
let value = itemlink.attr('href');
let jump;
//updateActiveLink(itemlink, 'link-active');
const jumpfrstElem = document.querySelector('.meta-faq-item[data-id=FAQitem1]').offsetTop;
const jumpElem = document.querySelector('.meta-faq-item[data-id=FAQitem' + value + ']').offsetTop;;
const jumpDiv = document.querySelector('.meta-about-content-right').offsetTop;
jumpfrstElem < jumpDiv ? jump = jumpElem + (jumpDiv - jumpfrstElem) - jumpDiv : jump = jumpElem - jumpDiv;
//const jump = jumpElem - jumpDiv;
//const jumpHeight
$('.meta-about-content-right[data-section=faq]').stop().animate({ scrollTop: jump }, 500);
//console.log(jumpElem, jumpDiv, $('.meta-about-content-right').outerHeight(), $('.meta-faq-item[data-id=FAQitem1]').offset().top, jump);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment