2011-08-28 47 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();