1

我这几天一直在做这件事,需要帮助。我知道如果图像缓存在 Safari 中,则不会调用 .load() 事件,所以我想出了下面的代码。

它可以判断图像是否已缓存,但无法获取缓存图像的宽度和高度。它出现为零(在 Safari 中)。任何见解将不胜感激。谢谢。

         var $_item = $('<div id="'+(name+itemIndex)+'" class="box" ><div class="image_back"><img src="'+ image_back +'" id="backcolor" /></div><div class="image_outline"><img src="'+ image_outline +'" /></div></div>').appendTo('body');

         if( $('#backcolor', $_item)[0].complete ) {
            el_w = $('#backcolor', $_item).width();
            el_h = $('#backcolor', $_item).height();
            console.log("cache*****" +":"+el_w+":"+":"+$('#backcolor', $_item)[0].width);

        } else {

            $('#backcolor', $_item).load( function() {
                el_w = $('#backcolor', $_item).width();
                el_h = $('#backcolor', $_item).height();
                console.log("load*****" + this+":"+el_w);

            });


        }
4

0 回答 0