Skip to content

Instantly share code, notes, and snippets.

@trepmal
Created November 15, 2011 00:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trepmal/1365731 to your computer and use it in GitHub Desktop.
Save trepmal/1365731 to your computer and use it in GitHub Desktop.
WordPress - Scroll-To-Top Admin Bar
<?php
/*
Plugin Name: Scroll-To-Top Admin Bar
Description: Click anywhere on the Admin Bar that doesn't have a predefined purpose (links, input), and it'll scroll you to the top
Author: Kailey Lampert
Author URI: http://kaileylampert.com
*/
add_action( 'wp_head', 'add_jq' );
add_action( 'admin_head', 'add_jq' );
function add_jq() {
wp_enqueue_script( 'jquery' );
}
add_action( 'wp_footer', 'add_jq_init' );
add_action( 'admin_footer', 'add_jq_init' );
function add_jq_init() {
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
$('#wpadminbar').click( function(e) {
tag = e.target.tagName;
if ( tag == 'DIV' ) {
$('html, body').animate({scrollTop:0}, 'fast');
return false;
}
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment