jQuery offset for anchor links - kary4/divituts GitHub Wiki

<script>

jQuery( document ).ready(function() {

setTimeout(function(){
	
(function($) {
$('a[href*=#]:not([href=#])').click(function() 
{
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) 
{
var target = $(this.hash),
headerHeight = $("#main-header").height() + 20; // Get fixed header height
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) 
{
$('html,body').animate({
scrollTop: target.offset().top - headerHeight
}, 500);
return false;
}
}
});
})(jQuery);
},1000);
}); 

</script>
<script>
jQuery(function($) {
  window.et_pb_smooth_scroll = function( $target, $top_section, speed, easing ) {
    var $window_width = $( window ).width();
    $menu_offset = -1;
    var headerHeight = 240;
    if ( $ ('#wpadminbar').length && $window_width <= 980 ) {
      $menu_offset += $( '#wpadminbar' ).outerHeight() + headerHeight;
    } else {
      $menu_offset += headerHeight;
    }
    //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>

https://gist.github.com/HoundstoothSTL/5510082

<script>
jQuery(function($) {
window.et_pb_smooth_scroll = function( $target, $top_section, speed, easing ) {
var $window_width = $( window ).width();
$menu_offset = -1;
var headerHeight = 98;
if ( $ ('#wpadminbar').length && $window_width <= 980 ) {
$menu_offset += $( '#wpadminbar' ).outerHeight() + headerHeight;
} else {
$menu_offset += headerHeight;
}
//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>
⚠️ **GitHub.com Fallback** ⚠️