javascript - 如何预加载iframe

标签 javascript jquery iframe jquery-animate preload

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/

相关文章:

jquery - Google 搜索结果样式的弹出窗口

javascript - 如何加载与 html 混合的 JavaScript

html - iframe 中的 Fullpage.js 无法在 IOS 移动设备上滚动

javascript - 如何在点击后延迟js功能

javascript - 使用嵌套的 try-catch block

javascript - METEOR 帐户 UI 登录按钮未显示在移动应用程序包装中

javascript - 点击无法解除绑定(bind)的问题

javascript - 监听元素前置

jquery - 如何创建从 CSS 下拉菜单到幻灯片 2 上的 iframe 的链接

javascript - 我想将不存在的项目推送到已声明的对象中(如果它们尚不存在),则使用 Angular 中的 lodash