resize无效无法实时获取width和heigh​,求解

function sizeAauto(){
    for(var i = 0;i <=$(".img_box").length;i++){
        ($(".img_box").eq(i)).append('<img src="img/x4.png" title="放大图片" class="img"/>');
        ($(".close").eq(i)).append('<img src="img/x5.png">');
        $(document).ready(function(){
            var imgWidth =  ($(".img_box").eq(i)).width();
            var imgHeight =  ($(".img_box").eq(i)).height();
            ($(".img_bg").eq(i)).css("width", imgWidth);
            ($(".img_bg").eq(i)).css("height", imgHeight);
            ($(".img_bg").eq(i)).css("line-height", imgHeight + 30 + "px");
            $(window).on("resize", function () {
                var imgWidth =  ($(".img_box").eq(i)).width();
                var imgHeight =  ($(".img_box").eq(i)).height();
                ($(".img_bg").eq(i)).css("width", imgWidth);
                ($(".img_bg").eq(i)).css("height", imgHeight);
                ($(".img_bg").eq(i)).css("line-height", imgHeight + 30 + "px");
                console.log( imgWidth);
            }(i));
            $(window).trigger("resize");
        }(i));
    }

加入for循环后, resize无效无法实时获取width和heigh

怪盗饭团
浏览 1505回答 1
1回答

一杯2块的奶茶

把html也发出来,我来本地研究下
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript