Preload iframe

落花浮王杯 提交于 2019-12-01 04:47:07

问题


        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);
        });

Hello stackoverflow,

A while ago i was trying to animate a div, well, it works now only one thing. When the first function is activated (starting row 3), and iframe gets loaded. But now, how can i preload that iframe? Because when the animation is finished the iframe isn't loaded...

Greetings


回答1:


With JQuery, you don't need to use iframes. Take a look at the .load() function. http://api.jquery.com/load

i.e.

$('#tempc').load('src/stream.php?stream=1');

To preload a page, just create a hidden div and show it when ready.

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



回答2:


Start by loading the iframe, hook into onLoad on the iframe (this might give you a headache in itself, but a little googling should show you how to make this work well cross browser) and run your animation from this event.



来源:https://stackoverflow.com/questions/4891029/preload-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!