.width returning incorrect value

.width returning incorrect value

Hi. I have a CSS media query with a breakpoint at 768px. My conditional in my jQuery is set to 768 but I realised that the .width element seems to be incorrect.

I did a little test, and when my breakpoint changes (at 768) the .width outputs 751 and therefore doesnt cut off the code at the right time. I also notice that if the browser is resized at speed it seems to be always different. This could be because of how I have my code setup.

  1.     function checkWidth() {
            var windowsize = $(window).width();
            if (windowsize < 768) {
                $('body').swipe('enable').swipe( {
                    swipeRight:function() {
                        $('body').addClass('js-nav');
                    },
                    swipeLeft:function() {
                        $('body').removeClass('js-nav');
                    }
                });
            } else {
                $('body').swipe('disable');
            }
        }
        checkWidth();
        $(window).resize(checkWidth);















Can anyone tell what the problem is? Is it something in my scripting? How can I ensure the .width is correct?