Skip to content

Instantly share code, notes, and snippets.

@Jursdotme
Created September 6, 2017 11:34
Show Gist options
  • Save Jursdotme/160255c9c3874c5d086bf3888c6e202e to your computer and use it in GitHub Desktop.
Save Jursdotme/160255c9c3874c5d086bf3888c6e202e to your computer and use it in GitHub Desktop.
/* ========== Smooth Scroll ========== */
(
function ( $ ) {
$.fn.vantageSmoothScroll = function () {
$( this ).click( function ( e ) {
var $a = $( this );
var $target = $( '[name=' + this.hash.slice( 1 ) + ']' ).length ? $( '[name=' + this.hash.slice( 1 ) + ']' ) : $( $a.get( 0 ).hash );
if ( $target.length ) {
var height = 0;
if ( $( '.site-navigation' ).hasClass( 'use-sticky-menu' ) ) {
height += $( '.site-navigation' ).outerHeight();
}
if ( $( 'body' ).hasClass( 'admin-bar' ) ) {
height += $( '#wpadminbar' ).outerHeight();
}
$( 'html, body' ).animate( {
scrollTop: $target.offset().top - height
}, 1000 );
return false;
}
// Scroll to the position of the item, minus the header size
} );
}
}
)( jQuery );
( function($) {
$(window).load( function() {
// Handle smooth scrolling
$( '#site-navigation a[href*="#"]:not([href="#"])' ).add( 'a[href*="#"]:not([href="#"])' ).not( '.lsow-tab a[href*="#"]:not([href="#"]), .wc-tabs a[href*="#"]:not([href="#"]), .iw-so-tab-title a[href*="#"]:not([href="#"]), .comment-navigation a[href*="#"]' ).vantageSmoothScroll();
} );
} )(jQuery);
@iwebroot
Copy link

Hello,
Thanks for this code but how to smooth scroll when page loaded please.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment