1

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?

ProEvilz
  • 5,310
  • 9
  • 44
  • 74
  • This question was answered here: https://stackoverflow.com/questions/28172955/jquery-animate-position-using-calc-as-value-subtract-px-from-percentage – Tony M Sep 13 '17 at 16:33
  • see your solution [here](https://stackoverflow.com/questions/30618392/jquery-animate-and-css-calc) – Animay Sep 13 '17 at 17:05

0 Answers0