Skip to content

Instantly share code, notes, and snippets.

@amboy00
Last active August 29, 2015 13:58
Show Gist options
  • Save amboy00/10024193 to your computer and use it in GitHub Desktop.
Save amboy00/10024193 to your computer and use it in GitHub Desktop.
One way to use RWD in JS.
jQuery(function ($) {
var width = window.innerWidth ? window.innerWidth : $(window).width(),
height = window.innerHeight ? window.innerHeight : $(window).height(),
touch = Modernizr.touch;
var breakpoint = function() {
if (width < 768) {
return 'small';
} else if (width < 992 ) {
return 'medium';
} else if (width < 1200 ) {
return 'large';
} else if (width < 1600 ) {
return 'x-large';
} else if (width >= 1600) {
return 'xx-large';
}
}
// Paul Irish Smart Resize plug in http://paulirish.com/2009/throttled-smartresize-jquery-event-handler/
$(window).smartresize(function(){
width = window.innerWidth ? window.innerWidth : $(window).width();
height = window.innerHeight ? window.innerHeight : $(window).height();
breakpoint();
});
if (!touch && ( breakpoint() != 'small' )) {
//I'm not a small display and I probably use a mouse
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment