Check width function help
Hi. I have made a small function to check the width of the browser, and included an if statement to run a piece of code.
- var $window = $(window);
function checkWidth() {
var windowsize = $window.width();
if (windowsize < 768) {
$('html').swipe( {
swipeRight:function() {
$('html').addClass('js-nav');
},
swipeLeft:function() {
$('html').removeClass('js-nav');
}
});
}
}
checkWidth();
$(window).resize(checkWidth);
The problem is, this works when the browser is large, and made smaller, but once the code is initialised it continues to work regardless if the browser is made larger than the condition.
How can I stop the code from working when the browser is increased to larger than 768?