| module.exports = function defaults (opts) { | ||
| opts = opts || {} | ||
| if (typeof opts.speed === 'undefined') opts.speed = 200 | ||
| return opts | ||
| } |
+9
-18
@@ -0,21 +1,12 @@ | ||
| var css = require('./css') | ||
| var defaults = require('./defaults') | ||
| var transition = require('./transition') | ||
| var defer = require('./defer') | ||
| var css = require('./css') | ||
| module.exports = function animates (el, start, end, opts) { | ||
| opts = opts || {} | ||
| clearTimeout(el._animates) | ||
| if (typeof opts.speed === 'undefined') opts.speed = 200 | ||
| el.style.transition = 'none' | ||
| css(el, start) | ||
| defer(doTransition) | ||
| function doTransition () { | ||
| el.style.transition = transition(end, opts.speed, opts.easing, opts.delay) | ||
| css(el, end) | ||
| el._animates = setTimeout(function finish () { | ||
| el.style.transition = 'none' | ||
| delete el._animates | ||
| }, Number(opts.speed || 200)) | ||
| } | ||
| module.exports = function animates (el, end, opts) { | ||
| opts = defaults(opts) | ||
| el.style.transition = transition(end, opts.speed, opts.easing, opts.delay) | ||
| css(el, end) | ||
| return setTimeout(function finish () { | ||
| el.style.transition = 'none' | ||
| }, opts.speed) | ||
| } |
@@ -10,3 +10,2 @@ var seconds = require('./seconds') | ||
| function tidbit (prop, speed, easing, delay) { | ||
| speed = speed || 200 | ||
| var bits = [prop, seconds(speed)] | ||
@@ -13,0 +12,0 @@ if (easing) bits.push(easing) |
+1
-1
| { | ||
| "name": "animates", | ||
| "version": "0.0.0", | ||
| "version": "0.0.1", | ||
| "description": "A small css3 animation lib inspired by jquery/animate", | ||
@@ -5,0 +5,0 @@ "main": "lib/animates.js", |
@@ -1,10 +0,29 @@ | ||
| /* globals describe it */ | ||
| var camel = require('../lib/camel') | ||
| /* globals describe beforeEach it */ | ||
| var animates = require('../lib/animates') | ||
| var expect = require('chai').expect | ||
| describe('camel', function () { | ||
| it('should camel case style declarations', function () { | ||
| expect(camel('margin-left')).to.eq('marginLeft') | ||
| expect(camel('padding-top')).to.eq('paddingTop') | ||
| describe('animate', function () { | ||
| var el | ||
| beforeEach(function () { | ||
| el = document.createElement('div') | ||
| el.setAttribute('style', 'width: 20px; height: 20px; background: black;') | ||
| document.body.appendChild(el) | ||
| }) | ||
| it('should camel case style declarations', function (done) { | ||
| animates(el, { opacity: 0 }, { speed: 100 }) | ||
| setTimeout(middle, 0) | ||
| setTimeout(end, 200) | ||
| function middle () { | ||
| expect(el.style.transition).to.eql('opacity 0.1s') | ||
| } | ||
| function end () { | ||
| expect(el.style.opacity).to.eql('0') | ||
| expect(el.style.transition).to.eql('none') | ||
| done() | ||
| } | ||
| }) | ||
| }) |
5205
6.16%16
6.67%138
8.66%