Created
August 17, 2023 07:33
-
-
Save Pavracer/03187c2b492fab8304fc9d746c39319e to your computer and use it in GitHub Desktop.
Anchor link position tweak
This file contains 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> | |
jQuery(function($) { | |
window.et_pb_smooth_scroll = function( $target, $top_section, speed, easing ) { | |
var $window_width = $( window ).width(); | |
$menu_offset = -12; | |
var headerHeight = 50; // for desktop | |
if ( $window_width <= 980 ) { | |
var headerHeight = 200; // for mobile value | |
} | |
$menu_offset += headerHeight; | |
if ( $ ('#wpadminbar').length && $window_width > 980 ) { | |
$menu_offset += $( '#wpadminbar' ).outerHeight(); | |
} | |
//fix sidenav scroll to top | |
if ( $top_section ) { | |
$scroll_position = 0; | |
} else { | |
$scroll_position = $target.offset().top - $menu_offset; | |
} | |
// set swing (animate's scrollTop default) as default value | |
if( typeof easing === 'undefined' ){ | |
easing = 'swing'; | |
} | |
$( 'html, body' ).animate( { scrollTop : $scroll_position }, speed, easing ); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment