I'm trying to subtract a value in pixels from a width value that is a percentage using jQuery.animate()
var fooPerc = 85; // Percent value
var fooWidth = 40; // pixels to subtract
$(el).animate({
left: fooPerc - fooWidth;
});
The above doesn't work.
So, I tried this
$(el).animate({
left: fooPerc+"%" - fooWidth+"px";
});
This doesn't work either.
According to other answers, you can usually use CSS3 Calc
E.G.
height: calc(100% - 18px);
But the problem is that calc
doesn't work with animate()
.
Is there any clean way I can do this?