ded / morpheus

A Brilliant Animator
504 stars 57 forks source link

Fix unit detection for negative values #48

Closed MartinodF closed 11 years ago

MartinodF commented 11 years ago

The regular expression used to extract the unit (%, em, ...) doesn't work with negative values (and plus-prefixed values, but that's just an edge case).

Adding a ? after the equal sign allows Morpheus to work correctly when animating to values such as -100%, -50px, -2cm and +150%.

A very common use case is writing carousels / page sliders et similia since we often want to animate left to -100%.

ded commented 11 years ago

good call. we need tests for this too

MartinodF commented 11 years ago

I added the simplest test I could think of, trying to be consistent with the already-existing ones. I rebased it on your master, I hope it's alright!

Note that I had to test a unit other than px (I used -10%) because morpheus defaults to pixels, so it would've worked anyway even if it discarded the unit. Also, I didn't add a test for plus-prefixed values. If you think I should, just tell me.

Edit: I haven't updated /morpheus.js and /morpheus.min.js, I'm not sure if I should have.

Thanks!

ded commented 11 years ago

this is perfect!