2011-08-28 46 views
0
function positionElements(){ 
     var vidHeight = $('#video').height; 
     var displace = parseInt(vidHeight, 10) * 0.8; 
     var topMargin = displace+'px'; 
     $('#video-overlay').offset($('#video').offset()).width($('#video').width()); 
     $('#video-overlay p').css('margin-top', topMargin); 
} 

我得到NaN這個..我以爲parseInt應該讓我過去。我需要在這裏執行乘法操作?與jQuery比例定位

回答

2

你的height後失蹤括號:

var vidHeight = $('#video').height(); 

沒有他們,你傳遞的對象height財產,並且該對象是jQuery的一個實例,即height屬性簡直就是jQuery height函數本身,而不是該函數的結果。

1

變化

var vidHeight = $('#video').height; 

進入

var vidHeight = $('#video').height();