2012-01-19 12 views
0

私のページにはモーダルウィンドウが設定されていますが、うまく機能しますが、ウィンドウのサイズを変更する必要があります。残念ながら、私は単にエラーが表示されます:ウィンドウサイズを変更するとウィンドウサイズが変わる "キャッチされていないタイプエラー"

Uncaught TypeError: Object # has no method 'outerHeight'

「this」は間違って使用していますか?

 $(window).resize(function() { 
      //If mask is open, resize modal elements 
      if ($('#modalMask').is(':visible')) { 
       //Resize and position modal windows 
       //Get window dimensions 
       var mWinHeight = $(window).height(); 
       var mWinWidth = $(window).width(); 
       //Make sure all open modal windows are centred 
       $('.modalWindow:visible').each(function (i) { 
        var $this = $(this); 
        $this.css('top', mWinHeight/2-(this.outerHeight()/2)); 
        $this.css('left', mWinWidth/2-(this.outerWidth()/2)); 
       }); 
      } 
     }); 

答えて

2

は、いくつかの「$」を忘れてしまった:outerHeightがDOMElementのの財産である場合

$this.css('top', mWinHeight/2-($this.outerHeight()/2)); 
$this.css('left', mWinWidth/2-($this.outerWidth()/2)); 
+0

私はばかです。ありがとう! –

+0

誰にでも起こります。心配ない。 – sje397

0

は私は知りませんが、あなたはjavascriptのプロパティを使用するには、括弧を削除するかがあります。

this.outerHeight 

又は.outerHeightを使用するthisからjQueryオブジェクトを作成()jqueryの方法:

$(this).outerHeight() 
// or use $this.outerHeight() 
+0

ありがとう、@ sje397あなたの前に瞬間を釘付け - 私は$が不足していた。 –

+0

問題はあなたの問題を解決したことです:o)上向き投票はまだ選択肢btwです;-) –

関連する問題