I make a simple check for the width of the screen to adapt, but something is wrong, here's the code:
var width = +$(window).width(); alert(width); //нормально выводит значение ширины окна if (width < 1024) { //не срабатывает в любом случае $('.fixed-1').css("position", "relative"); } else{ alert(width < 1024); //выводит всегда false var width_true = $('#menu2').width(); $('.fixed-l').css("max-width", width_true); $('.fixed-l').css(" position", "fixed"); } Even when the window is less than 1024 pixels, it returns false . What's the matter?
alert(width < 1024);it runs ifwidth>=1024, so the condition will always befalse. The error is not in the code, but in the logic. - Sergey Glazirin