I need to bypass some javascript code in a responsive design that supports wide, normal, and narrow widths. I need to bypass the code when in "wide" mode. I could write something like this:
if ($('#page').width() < 1237) {
... do the animation stuff
}
Is there better way to do this that would avoid hard-coding pixel widths?
I was thinking that I could apply a class to the body element when the window is resized... something like:
if (width >= 1237) {
$('body').removeClass('layout-normal').removeClass('layout-ipad').addClass('layout-wide');
}
else if (width >= 980) {
$('body').removeClass('layout-wide').removeClass('layout-ipad').addClass('layout-normal');
}
else {
$('body').removeClass('layout-wide').removeClass('layout-normal').addClass('layout-ipad');
}
This would allow me to isolate the hard-coded widths to a single function, and then I could write:
if (!$('#page').hasClass('layout-wide') {
... do the animation stuff
}
But is there a way to avoid hard-coding pixel widths altogether?