【问题标题】:How to preload iframe如何预加载 iframe
【发布时间】:2011-02-03 20:00:08
【问题描述】:
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 没有加载。

【问题讨论】:

    标签: javascript jquery iframe jquery-animate preload


    【解决方案1】:

    使用 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());
    

    【讨论】:

      【解决方案2】:

      从加载 iframe 开始,连接到 iframe 上的 onLoad(这本身可能会让您头疼,但稍微用谷歌搜索一下应该会告诉您如何使它在跨浏览器上正常工作)并从此事件运行您的动画.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-23
        • 1970-01-01
        • 2012-03-28
        相关资源
        最近更新 更多