预加载iframe

The*_*hew 4 javascript iframe jquery preload jquery-animate

        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);
        });
Run Code Online (Sandbox Code Playgroud)

Hello stackoverflow,

不久之前,我试图为div设置动画,好吧,它现在只有一件事.第一个函数被激活时(从第3行开始),iframe被加载.但是现在,我怎么能预加载那个iframe?因为动画结束时iframe没有加载...

问候

js1*_*568 6

使用JQuery,您不需要使用iframe.看一下.load()函数.http://api.jquery.com/load

$('#tempc').load('src/stream.php?stream=1');
Run Code Online (Sandbox Code Playgroud)

要预加载页面,只需创建一个隐藏的div并在准备好时显示它.

var stream2 = $('<div>').load('src/stream.php?stream=2').hide();
$('#tempc').html(stream2.html());
Run Code Online (Sandbox Code Playgroud)