Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active October 27, 2020 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wplit/ce881c9ee57b11df0d687b671effccfc to your computer and use it in GitHub Desktop.
Save wplit/ce881c9ee57b11df0d687b671effccfc to your computer and use it in GitHub Desktop.
link to accordion item inside Pro Accordion component (when using acf repeaters) with hashlink from another page
/*
With this you can customise the ID of the accordion in dynamic mode.. say it's #pricing-faq
Then to link to the 3rd item in that accordion, it would be example.com/#pricing-faq-3
Change the 1000ms, to whatever delay you need for opening the accordion and scrolling
*/
jQuery(document).ready(function($) {
var hash = window.location.hash.substr(1);
if (hash !== '') {
var element = $('#header' + hash);
setTimeout(function() {
// Only if element is found and is part of a Pro Accordion item
if (element.length && element.parent('.oxy-pro-accordion_item').length) {
// Open up the accordion & move focus
element.trigger('click');
element.focus();
// scroll to the element.
$([document.documentElement, document.body]).animate({
scrollTop: element.offset().top - 100
}, 1000); // 1000ms delay before scrolling
}
}, 1000); // 1000ms delay before opening the accordion item
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment