/    Sign up×
Community /Pin to ProfileBookmark

Accordion link scroll to top

Hi!

I have some issues with my accordions build with elementor.

I want the #tab to scroll to the top of the page (y=0px).

What do I have to change in this code?

` // scroll to
var headerHeight = $(‘#header’).height() // put here your header id to get its height.
$([document.documentElement, document.body]).animate({
scrollTop: $(‘.elementor-tab-title[data-tab=”‘ + current[1] + ‘”]’).closest(‘.elementor-widget-wrap’).offset().top – headerHeight
}, 2000)`

This is the code so far:

`add_action( ‘wp_head’, function () { ?>
<script type=”text/javascript”>
jQuery(document).ready(function ($) {
//get the hash tag
//hash exist
setTimeout(function () {
var current = window.location.href
var current = current.split(‘#tab’)
if (current.length > 1) {
showAndScrollToTab($, current)
}
}, 200);
// change the browser url according to selected tab
$(‘.elementor-tab-title[data-tab]’).click(function () {
var current_location = window.location.href;
current_location = current_location.split(‘#’)
window.location = current_location[0] + ‘#tab’ + $(this).attr(‘data-tab’)
})
// activate tab also from anchor link in the same page
$(‘a’).on(‘click’, function () {
var anchorUrl = $(this).attr(‘href’)
var anchor = anchorUrl.split(‘#tab’)
if (anchor.length > 1) {
showAndScrollToTab($, anchor)
}
})
})

function showAndScrollToTab($, current) {
$(‘.elementor-tab-content’).removeClass(‘elementor-active’).css(‘display’,’none’)
$(‘.elementor-tab-content[data-tab=”‘ + current[1] + ‘”]’).addClass(‘elementor-active’).css(‘display’,’block’)
$(‘.elementor-tab-content’).hide();
$(‘.elementor-tab-content[data-tab=”‘+current[1]+'”]’).show();
// scroll to
var headerHeight = $(‘#header’).height() // put here your header id to get its height.
$([document.documentElement, document.body]).animate({
scrollTop: $(‘.elementor-tab-title[data-tab=”‘ + current[1] + ‘”]’).closest(‘.elementor-widget-wrap’).offset().top – headerHeight
}, 2000)
}
</script>
<?php } );
`

Thanks a lot!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @kulaber spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 9.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @ddiebold17,
tipped: article
amount: 1000 SATS,

tipper: @Mqlinka19,
tipped: live stream
amount: 4900 SATS,

tipper: @Mqlinka19,
tipped: article
amount: 10 SATS,
)...