Last active
August 29, 2015 13:58
-
-
Save amboy00/10024193 to your computer and use it in GitHub Desktop.
One way to use RWD in JS.
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
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