function toggle(){
$("#tempc").toggle(
function () {
$("#tempc").animate({width: 255, height: 220}, 1000);
$("#tempc").html("");
$("#tempc").css("background-color", "transparent");
$("#tempc").html("<iframe src='/src/stream.php?stream=1' width='255' height='225' frameborder='0' scrolling='no'></iframe><br><a href='javascript:;' onclick='hidegadget();' class='yellowblock'>Sluit</a>");
},
function () {
$("#tempc").animate({width: 50, height:50}, 1000);
$("#tempc").html("");
$("#tempc").css("background-color", "#FFFF00");
$.get('src/stream.php?stream=2', function(data002) {
$('#tempc').html(data002);
});
}
);
}
$.get('src/stream.php?stream=2', function(data002) {
$('#tempc').html(data002);
});
不久前,我试图为一个 div 设置动画,好吧,它现在只能做一件事。 当第一个函数被激活时(从第 3 行开始),iframe 被加载。但是现在,我如何预加载该 iframe?因为当动画完成时,iframe 没有加载。
最佳答案
使用 JQuery,您不需要使用 iframe。看一下 .load() 函数。 http://api.jquery.com/load
即
$('#tempc').load('src/stream.php?stream=1');
要预加载页面,只需创建一个隐藏的 div 并在准备就绪时显示它。
var stream2 = $('<div>').load('src/stream.php?stream=2').hide();
$('#tempc').html(stream2.html());
关于javascript - 如何预加载iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4891029/