This solution will also work if the fields are set as a percentage, but it may be enough for your purposes. Basically, you record which fields change when you resize. Thus, you must write the fields before resizing to the array:
var aMargins = []; $('.yourObjs').each(function(i,obj){ var objML = $(obj).css('marginLeft'); aMargins.push(objML); });
Then resize the window, see which fields have changed (it will be either βautoβ or%), do what you need to do, and return it to its original size:
var wW = $(window).width(); var wH = $(window).height(); window.resizeTo(wW - 5, wH); $('.yourObjs').each(function(i,obj){ if ($(obj).css('marginLeft') != aMargins[i]) {
If your centering code just adjusts the left margin, then this should work fine for percent fields too. I canβt check this code or give an example, because Iβm on the road and writing from the phone, but I hope this works or helps you come up with something that will happen.
mVChr source share