Last active
October 27, 2020 08:52
-
-
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
This file contains hidden or 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
| /* | |
| 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