Skip to content

Instantly share code, notes, and snippets.

@Jursdotme
Created April 18, 2017 14:05
Show Gist options
  • Save Jursdotme/981bffd9d1b4fd318cb755b19d9bf049 to your computer and use it in GitHub Desktop.
Save Jursdotme/981bffd9d1b4fd318cb755b19d9bf049 to your computer and use it in GitHub Desktop.
Smooth scroll vantage
( 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 ( $( '#masthead .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 );
console.log(height);
return false;
}
// Scroll to the position of the item, minus the header size
} );
}
$(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);
$settings->add_field('navigation', 'smooth_scroll', 'checkbox', __('Smooth scrolling.', 'vantage'), array(
'description' => __('Enables smooth scroll for internal anchor links.', 'vantage')
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment