随着窗口变大,div的左边距也拉大

            var winW = parseInt(jQuery(document).width());
            var maxw = (winW - parseInt(jQuery("#ifocus_pic").width())) / 2;
            var ipc = document.getElementById("ifocus_pic");
            ipc.style.marginLeft = maxw + 'px';
            var minw = parseInt(jQuery("#ifocus_btn").width());
            window.onresize = function() {
                var w3 = parseInt(jQuery(document).width());
                var num = parseInt(ipc.style.marginLeft);
                if (w3 < winW) {
                    if (num > minw) {
                        ipc.style.marginLeft = (parseInt(ipc.style.marginLeft) - 1) + "px";
                    }
                }
                if (w3 > winW) {
                    if (num < maxw) {
                        ipc.style.marginLeft = (parseInt(ipc.style.marginLeft) + 1) + "px";
                    }
                }
                winW = w3;
            }


你可能感兴趣的:(jquery,function,div)