Fork me on GitHub

Move

Move makes animating the properties of DOM/SVG elements easy with a clean expressive API. Combine it with something to manage the timing between animations and you can really make your page dance.

Limitations

Advantages

Examples

Move#set(prop, val)

Set prop to val.

move(box)
  .set('margin-left', 200)
  .run('1s')
  

Move#add(prop, val)

Increment prop by val, where val is an Number (click several times).

move(box)
  .add('margin-left', 200)
  .run('1s')
  

Move#sub(prop, val)

Decrement prop by val, where val is an Number (click several times).

move(box)
  .sub('margin-left', 100)
  .run('1s')
  

Move#rotate(deg)

Rotate by deg.

move(box)
  .rotate(140)
  .run('1s')
  

Move#duration(n)

Set animation duration to n which is a Number or a string such as "4s".

move(box)
  .set('background-color', 'blue')
  .duration('2s')
  .run()
  

Move#translate(x[, y])

Translate x and optionally y axis.

move(box)
  .translate(100, 20)
  .run('1s')
  

Move#x(n) / Move#y(n)

Translate x or y axis. Aliased by Move#translateX(n) and Move#translateY(n).

move(box)
  .x(100)
  .y(20)
  .run('1s')
  

Move#skew(x[, y])

Skew x, and optionally y. Move#skewX(n) and Move#skewY(n) are also available.

move(box)
  .skew(50)
  .run('1s')
  

Move#scale(x[, y])

Scale the x, and optionally y axis. Move#scaleX(n) and Move#scaleY(n) are also available.

move(box)
  .scale(3)
  .run('1s')
  

Move#then(fn)

The then() method triggers the animation to run. Optionally you can pass in a callback fn to call when the animation completes.

move(box)
  .set('background-color', 'blue')
  .duration('1s')
  .then(function(){
    move(box)
      .set('background-color', 'aliceblue')
      .run('1s')
  })
  

Move#then([move])

Creates a DeferredMove which will be run when this move completes. Optionally you can pass in a Move instance and it will be run on completion of this animation.

var moveBack = move(boxs[0])
  .duration(500)
  .set('background-color', 'aliceblue')
  .x(0)
  
move(boxs[0])
  .duration('1s')
  .set('background-color', 'blue')
  .x(500)
  .then(moveBack)
  
move(boxs[1])
  .duration(500)
  .set('background-color', 'blue')
  .x(500)
  .scale(.5)
  .rotate(60)
  .then()
    .rotate(30)
    .scale(2)
    .set('border-radius', 5)
    .set('opacity', 0)
    .then()
      .rotate(270)
      .x(-500)
      .set('background-color', 'aliceblue')
      .set('border-radius', 0)
      .set('opacity', 1)
      

Move#ease(fn)

Use the given easing fn. The default function is "linear". For a complete list of available functions see component/ease

linear
in-quad
out-quad
in-out-quad
boxs.forEach(function(box){
  move(box)
    .duration('1s')
    .ease(box.textContent)
    .x(400)
    .then()
      .x(-400)
})

Move#render(n)

render allows you to control the animation

var anim = move(box).set('d', '\
  m 300,150 \
  c 0,50 -50,50 -50,0 \
  s -50,-50 -50,0 \
  s -50,50 -50,0 \
  s -50,-50 -50,0')
example.find('input').on('change', function(e){
  anim.render(this.value/100)
})

Move(svg)

Move handles SVG elements transparently. Just go ahead and use all the same methods.

move(box)
  .set('d', '\
    m 200 50 \
    l 100 100 \
    l -100 100 \
    l -100 -100 \
    l 100 -100')
  .ease('out-sine')
  .duration('.5s')
  .then()
    .set('d', '\
      m 300,150 \
      c 0,50 -50,50 -50,0 \
      s -50,-50 -50,0 \
      s -50,50 -50,0 \
      s -50,-50 -50,0')
    .then()
      .set('d', '\
        m 200 100 \
        l 50 47 \
        a 6 6 0 0 1 0 6 \
        l -50 47 \
        l 0 -100')