Created
July 27, 2013 04:18
-
-
Save norcross/6093688 to your computer and use it in GitHub Desktop.
run various JS stuff on widths
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
//******************************************************** | |
// 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