Skip to content

Instantly share code, notes, and snippets.

@SimonS
Created March 8, 2012 16:35
Show Gist options
  • Save SimonS/2001962 to your computer and use it in GitHub Desktop.
Save SimonS/2001962 to your computer and use it in GitHub Desktop.
Minimal reponsive javascript framework
(function($){
var previous_state = '',
state;
$(function(){
// Resize event
var resizeTimer = null; /* use resizeTimer to minimise lag */
$(window).resize( function(){
if(resizeTimer) {
clearTimeout( resizeTimer );
}
resizeTimer = setTimeout( function(){
var TABLET = 768,
DESKTOP = 1100;
previous_state = state;
if( $(document).width() < TABLET ) {
state = 'MOBILE';
}
if( $(document).width() >= TABLET && $(document).width() < DESKTOP ) {
state = 'TABLET';
}
if( $(document).width() >= DESKTOP ) {
state = 'DESKTOP';
}
$(document).trigger(state);
}, 200 );
} ).trigger( 'resize' );
});
var add_show_hide = function() {
// implement function to add show hide button to div
};
var remove_show_hide = function() {
// implement function to remove show hide button from div
};
// Attach functions to responsive events:
$( document ).live( 'MOBILE', add_show_hide );
$( document ).live( 'TABLET DESKTOP', remove_show_hide );
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment