[ad_1]
I think i’ve made it. At least i think so.
const tabOpener = function(tab) {
// Simulate a click on that tab.
if (typeof tab === 'string') {
const currentTab = jQuery('.' + tab + '_tab');
currentTab.children('a').click();
}
// Scroll to that tab.
jQuery('html, body').animate(
{
scrollTop: jQuery('#tab-' + tab).offset().top - $('.site-header').height()
},
300,
function() {
// Update the URL hash after scrolling is complete.
window.location.hash = tab;
}
);
};
jQuery(document).ready(function($) {
const { hash } = window.location;
let tab;
// If a # exists in the URL, let's see if it's a tab.
if (hash) {
tab = hash.replace('#', '');
tabOpener(tab);
}
// On click, we'll check to see if the event target has a tab hash.
$('body').on('click', function(e) {
if (e.target.hash && !e.target.hash.includes('#tab')) {
tab = e.target.hash.replace('#', '');
tabOpener(tab);
}
});
});
