Last active
January 3, 2016 07:09
-
-
Save rickrduncan/8428019 to your computer and use it in GitHub Desktop.
jQuery for smooth scrolling to top of page.
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
<?php | |
//* Do NOT include the opening php tag | |
//* Add Core JS file | |
add_action( 'wp_enqueue_scripts', 'b3m_add_core_js' ); | |
if ( ! function_exists( 'b3m_add_core_js' ) ) { | |
function b3m_add_core_js() { | |
wp_enqueue_script( 'core-js', get_stylesheet_directory_uri() . '/lib/js/core.js', array('jquery'), '1.0.0', true ); | |
} | |
} |
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
<!-- Create a hyperlink and assign it the class 'smooth-scroll' --> | |
<a class="smooth-scroll" href="#" title="top of page" rel="nofollow">Top of Page</a> |
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
//* Smooth scrolling | |
jQuery(document).ready(function() { | |
var duration = 800; | |
jQuery('.smooth-scroll').click(function(event) { | |
event.preventDefault(); | |
jQuery('html, body').animate({scrollTop: 0}, duration); | |
return false; | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment