convert decimals into negatives?
I'm scaling an image in css with transforms.
The 开发者_Python百科scale goes from 0 to whatever, with 0 through 1 being smaller than the image.
I need to get the scale into negatives, so that 0 is the same size as the original, 1 is double the size, and -1 is half the size.
I have vars:
var cssScale, factorScale;
How to get cssScale into factorScale and vice versa?
Thanks.
Seems like you want 2-to-the-power-of-n:
cssScale= Math.pow(2, factorScale);
To get back the other way would be log-base-2, which you'd have to implement using log-base-E:
factorScale= Math.log(cssScale)/Math.LN2;
Sounds like cssScale = Size * (2 ^ factorScale).
精彩评论