Skip to content

Instantly share code, notes, and snippets.

@norcross
Created July 27, 2013 04:18
Show Gist options
  • Save norcross/6093688 to your computer and use it in GitHub Desktop.
Save norcross/6093688 to your computer and use it in GitHub Desktop.
run various JS stuff on widths
//********************************************************
// run size checks
//********************************************************
function between(x, min, max) {
return x >= min && x <= max;
}
//********************************************************
// now start the engine
//********************************************************
jQuery(document).ready( function($) {
//********************************************************
// add body classes for viewports
//********************************************************
var item_width = $('div.whatever').width();
if ( site_width < 600 ) {
// do something
}
if ( between( site_width, 600, 727 ) ) {
// do something
}
if ( between( site_width, 728, 949 ) ) {
// do something
}
if ( site_width > 949 ) {
// do something
}
$(window).resize(function() {
var new_width = $('div.whatever').width();
if ( new_width < 600 ) {
// do something
}
if ( between( new_width, 600, 727 ) ) {
// do something
}
if ( between( new_width, 728, 949 ) ) {
// do something
}
if ( new_width >949 ) {
// do something
}
});
//********************************************************
// you're still here? it's over. go home.
//********************************************************
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment