Created
April 18, 2017 14:05
-
-
Save Jursdotme/981bffd9d1b4fd318cb755b19d9bf049 to your computer and use it in GitHub Desktop.
Smooth scroll vantage
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
( 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); |
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
$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