4
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をアニメーション化しようとしていましたが、今では1つしか機能しません。最初の関数がアクティブ化されたとき(行3から開始)、iframeが読み込まれます。しかし今、どうすればそのiframeをプリロードできますか?アニメーションが終了すると、iframeが読み込まれないためです。

4

2 に答える 2

6

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());
于 2011-02-03T20:34:58.253 に答える
1

iframeをロードすることから始め、iframeに接続しonLoadて(これ自体が頭痛の種になる可能性がありますが、少しグーグルすると、ブラウザー間でこれをうまく機能させる方法がわかります)、このイベントからアニメーションを実行します。

于 2011-02-03T20:06:48.900 に答える