Skip to content

Instantly share code, notes, and snippets.

@siamkreative
Created February 17, 2015 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siamkreative/57f53e505b1b6dabf5d6 to your computer and use it in GitHub Desktop.
Save siamkreative/57f53e505b1b6dabf5d6 to your computer and use it in GitHub Desktop.
Update Javascript Variable if WordPress Admin Bar is enabled
jQuery(document).ready(function ($) {
// The long version
var scrollOffset;
if ($('body').hasClass('admin-bar')) {
scrollOffset = 64;
} else {
scrollOffset = 32;
}
// The slightly shorter version
var scrollOffset;
if ($('body').hasClass('admin-bar'))
scrollOffset = 64;
else
scrollOffset = 32;
// The shorthand
var scrollOffset = $('body').hasClass('admin-bar') ? 64 : 32;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment