I\'m working on a mobile version of my site. I\'m using media queries and CSS as much as possible, but I\'m also using some javascript to, for example, turn my navigation in
@3stripe has the correct answer.
This is just a slight modification which makes it more efficient by caching the window object rather than repeatedly instantiating jQuery (keep in mind the resize
event may be called rapidly on an actual resize).
jQuery(document).ready(function($) {
// Cached window jQuery object
var $window = $(window);
// Store the window width
var windowWidth = $window.width();
// Resize Event
$window.resize(function(){
// Check window width has actually changed and it's not just iOS triggering a resize event on scroll
if ($window.width() != windowWidth) {
// Update the window width for next time
windowWidth = $window.width();
// Do stuff here
}
// Otherwise do nothing
});
});