3

ブラウザのサイズ変更イベントをキャッチする次のコードがあります。

 window.onresize = function(){
 var style = $('#button-selection').position();
 if(style == "relative"){
 $("#button-section").css("position"," ");
 }else if(style == "fixed"){
    $("#button-section").css("position","relative");
 }              
 };


 window.onresize = function(){
            var style = $('#button-selection').css('position');
            if(style == "relative"){
                $("#button-section").css("position"," ");
            }else if(style == "fixed"){
                $("#button-section").css("position","relative");
            }               
        };

スタイルは undefined を返します。ドキュメントの準備ができたら、これを実行しています。window ready を使用してみましたが、結果は同じです。上記のメソッドはどちらも undefined を返します!

4

2 に答える 2

1

jQueryのドキュメントによると、 .position() は次のとおりです。

説明: 一致した要素のセット内の最初の要素の現在の座標を、オフセットの親を基準にして取得します。

あなたが使用する必要があります:

 var style = $('#button-selection').css('position');
于 2013-04-11T07:59:12.970 に答える