0

誰かが私がこれを解決するのを手伝ってくれませんか。

jqueryを使用してブラウザウィンドウに合うようにフラッシュオブジェクト/埋め込みコードのサイズを変更しています。以下のHTMLを参照してください。

HTML

<div id="prezi">

     <object id="prezi_3453246342644353463435463456435" width="1000" height="800">

          <embed width="1000" height="800" ></embed>

     </object>

</div>

JQUERY(THIS WORKS)

function preziresize() {

    var $objectId =       $('#prezi_3453246342644353463435463456435'),
        $objectEmbed =    $objectId.find('embed'),
        windowWidth =     $(window).width(),
        windowHeight =    $(window).height();

        $objectId.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );

        $objectEmbed.attr( 'height' , windowHeight ).attr( 'width' , windowWidth ); 

}

$(document).ready(function() {

    preziresize();

});

$(window).resize(function() {

    preziresize();

});


私の問題

ただし、上記のスクリプトの欠点は、オブジェクトのIDを手動でスクリプトに入力する必要があることです。:(

動作していない新しいスクリプトで、オブジェクトのIDを自動的に取得し、それを変数として割り当てようとしています。以下の私の機能をご覧ください。

function preziresize() {

    var $objectId =     $('#prezi').attr( 'id' ),
        $objectEmbed =  $objectId.find('embed'),
        windowWidth =   $(window).width(),
        windowHeight =  $(window).height();

        $objectId.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );

        $objectEmbed.attr( 'height' , windowHeight ).attr( 'width' , windowWidth ); 

}


どんなポインタでも大いに感謝します。

ジョシュ

4

3 に答える 3

3

編集:サイズ変更時にも実行する方がよいでしょう。

$(window).bind("resize.preziresize", function() {
   $('div#prezi object')
       .find('embed')
       .andSelf()
       .attr( 'height' , $(window).height() )
       .attr( 'width' , $(window).width() );
}).trigger("resize.preziresize");
于 2012-04-05T10:34:12.617 に答える
2
var $object =     $('#prezi').find("object"),
    $objectEmbed =  $object.find('embed'),
于 2012-04-05T10:34:04.157 に答える
-1

このコードはあまり意味がありません。sinse$( "#prezi")は、それがidであり、"prezi"であることをすでに知っていることを意味します。コードのもう1つの問題は、$ objectIdが文字列であり、jQueryオブジェクトではないため、.findを使用できないことです。これを試して:

function preziresize() {    
    var $object =       $('#prezi object'),
        $objectId =     $object.attr('id')
        $objectEmbed =  $object.find('embed'),
        windowWidth =   $(window).width(),
        windowHeight =  $(window).height();

        $object.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );
        $objectEmbed.attr( 'height' , windowHeight ).attr( 'width' , windowWidth ); 
}
于 2012-04-05T10:36:57.120 に答える