Created
September 30, 2021 08:53
-
-
Save Pavracer/2f08282cdbecaef6ecefda11043f83d5 to your computer and use it in GitHub Desktop.
Accordion and Toggle Speed
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
<script> | |
(function($) { | |
$( 'body' ).on( 'click', '.et_pb_toggle_title, .et_fb_toggle_overlay', function() { | |
var $this_heading = $(this), | |
$module = $this_heading.closest('.et_pb_toggle'), | |
$section = $module.parents( '.et_pb_section' ), | |
$content = $module.find('.et_pb_toggle_content'), | |
$accordion = $module.closest( '.et_pb_accordion' ), | |
is_accordion = $accordion.length, | |
is_accordion_toggling = $accordion.hasClass( 'et_pb_accordion_toggling' ), | |
window_offset_top = $(window).scrollTop(), | |
fixed_header_height = 0, | |
initial_toggle_state = $module.hasClass( 'et_pb_toggle_close' ) ? 'closed' : 'opened', | |
$accordion_active_toggle, | |
module_offset; | |
if ( is_accordion ) { | |
if ( $module.hasClass('et_pb_toggle_open') || is_accordion_toggling ) { | |
return false; | |
} | |
$accordion.addClass( 'et_pb_accordion_toggling' ); | |
$accordion_active_toggle = $module.siblings('.et_pb_toggle_open'); | |
} | |
if ( $content.is( ':animated' ) ) { | |
return; | |
} | |
$content.slideToggle(1000, function () { | |
et_toggle_animation_callback(initial_toggle_state, $module, $section); | |
}); | |
if ( is_accordion ) { | |
$accordion_active_toggle.find('.et_pb_toggle_content').slideToggle( 700, function() { | |
$accordion_active_toggle.removeClass( 'et_pb_toggle_open' ).addClass('et_pb_toggle_close'); | |
$accordion.removeClass( 'et_pb_accordion_toggling' ); | |
module_offset = $module.offset(); | |
// Calculate height of fixed nav | |
if ( $('#wpadminbar').length ) { | |
fixed_header_height += $('#wpadminbar').height(); | |
} | |
if ( $('#top-header').length ) { | |
fixed_header_height += $('#top-header').height(); | |
} | |
if ( $('#main-header').length && ! window.et_is_vertical_nav ) { | |
fixed_header_height += $('#main-header').height(); | |
} | |
// Compare accordion offset against window's offset and adjust accordingly | |
if ( ( window_offset_top + fixed_header_height ) > module_offset.top ) { | |
$('html, body').animate({ scrollTop : ( module_offset.top - fixed_header_height - 50 ) }); | |
} | |
} ); | |
} | |
} ); | |
function et_toggle_animation_callback( initial_toggle_state, $module, $section ) { | |
if ( 'closed' === initial_toggle_state ) { | |
$module.removeClass('et_pb_toggle_close').addClass('et_pb_toggle_open'); | |
} else { | |
$module.removeClass('et_pb_toggle_open').addClass('et_pb_toggle_close'); | |
} | |
if ( $section.hasClass( 'et_pb_section_parallax' ) && !$section.children().hasClass( 'et_pb_parallax_css') ) { | |
$.proxy( et_parallax_set_height, $section )(); | |
} | |
} | |
})(jQuery); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment