开发者

Proportional positioning with jQuery

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);
}

I'm getting NaN for this.. I thought parseInt was supposed to get me past that. What do I need to do to perform multiplication in here?


You're missing the parentheses after the height:

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

Without them, you are passing in the height property of the object, and as that object is an instance of jQuery, the height property is simply the jQuery height function itself, rather than the result of that function.


Change

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

Into

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜