Created
March 8, 2012 16:35
-
-
Save SimonS/2001962 to your computer and use it in GitHub Desktop.
Minimal reponsive javascript framework
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
(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