将preload img转换为iframe [英] convert preload img to iframe
本文介绍了将preload img转换为iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$('<img />')
.attr('src', val)
.attr('width', "400")
.load(function(){
$('.showdata').append( $(this) );
}
);
这适用于图片,如何将1:1转换为iframe?
这里快速jsfiddle:
http://jsfiddle.net/ET8Gw/
This works perfectly for images, how would this convert 1:1 to iframes? Here quick jsfiddle: http://jsfiddle.net/ET8Gw/
推荐答案
与Image对象不同,IFrame在它们成为DOM的一部分之前不会加载。
Unlike Image objects, IFrames will not load until they are part of the DOM.
要解决此问题,您可以隐藏元素,将其添加到DOM,以及加载事件触发时显示它:
To get around this you can hide the element, add it to the DOM, and when the load event fires show it:
var val = "http://dumb.com/";
$('<iframe />')
.hide()
.attr('src', val)
.attr('width', "500")
.load(function(){
$(this).show();
})
.appendTo(".showdata");
这篇关于将preload img转换为iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文