Support animating DOM properties like scrollTop #28

Merged
merged 1 commit into from Aug 5, 2016

Projects

None yet

2 participants

@perrin4869
Contributor

Before, only properties inside style were animated by dynamics.js. This PR first checks for properties belonging to the element, and then opts to animate style properties. I think this falls in line with how dynamics.js animates arbitrary javascript objects too.

@michaelvillar michaelvillar and 1 other commented on an outdated diff Aug 4, 2016
src/dynamics.coffee
@@ -71,7 +71,10 @@ applyProperties = (el, properties) ->
if isSVG && svgProperties.contains(k)
el.setAttribute(k, v)
else
- el.style[propertyWithPrefix(k)] = v
+ if k of el # support animating scrollTop, etc
@michaelvillar
michaelvillar Aug 4, 2016 Owner

Combine this with the parent else?

@perrin4869
perrin4869 Aug 5, 2016 Contributor

done :)

@michaelvillar michaelvillar commented on the diff Aug 4, 2016
test/dynamics.coffee
@@ -73,6 +73,19 @@ describe 'dynamics.animate', ->
done()
, 50
+ it 'animate scrollTop of a DOM element', (done) ->
+ el = document.createElement('div')
+ dynamics.animate(el, {
+ scrollTop: 100,
+ }, {
+ duration: 25,
+ type: dynamics.easeInOut
+ })
+ setTimeout ->
+ expect(el.scrollTop).eql('100')
+ done()
+ , 50
+
@michaelvillar
michaelvillar Aug 4, 2016 Owner

Thanks for the tests!

@perrin4869
Contributor

done :)

@michaelvillar
Owner

Thanks a lot! 💯

@michaelvillar michaelvillar merged commit 16440ca into michaelvillar:master Aug 5, 2016
@perrin4869
Contributor

Sure! Could you make a new release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment