I am new to js and a bit stuck (with something that is probably very ease to fix)
I have worked out the height of a div, but I want the variable to be a negative value (so i can centre something horizontally)
Here is the wrong jquery
var modal_height = $('#modal div').outerHeight()/2;
$('#modal div').css('m开发者_开发问答arginTop','-'+modal_height);
Basically as you can see im trying to make the final marginTop value a negative one (i.e. adding a minus sign before the variable)
What is the correct syntax?
You need to use the unary minus operator: -modal_height
.
This operator returns a negative number.
(If the original number is already negative, it will return a positive number instead)
精彩评论