resize - JQuery change css class and div position when resizing window -


helo

i wrote code change css value 'left' depend on window size. have problems change class when window smaller body width. class jump between old , new class.

jquery:

    $(document).ready(function() {         $(window).resize(function() {             var bodywidth = $("body").css("width").replace("px","");             var winwidth = $(window).width();             if (bodywidth<winwidth) {                 var left = $(".menu").css("left").replace("px","");                 $("#menus").css("left" , (winwidth - bodywidth) / 2 + 2 + "px");                 }             if (bodywidth>winwidth) {                 $("#menus").toggleclass("menu popr");             }         }).resize();      }); 

here example of use: http://jsfiddle.net/zolkovv/u2q65/


Comments