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();
精彩评论