Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Forked from minodisk/cssTo.coffee
Created May 7, 2012 10:08
Show Gist options
  • Select an option

  • Save tanepiper/2627022 to your computer and use it in GitHub Desktop.

Select an option

Save tanepiper/2627022 to your computer and use it in GitHub Desktop.
CSS animation with callback style
cssTo = (elem, prop, time, easing, callback)->
time = "#{time / 1000}s"
transitions = []
for key, value of prop
transitions.push "#{key} #{time} #{easing}"
transition = transitions.join ', '
listener = (e)->
elem.removeEventListener 'webkitTransitionEnd', listener
elem.style['-webkit-transition'] = ''
callback?()
elem.addEventListener 'webkitTransitionEnd', listener
elem.style['-webkit-transition'] = transition
for key, value of prop
elem.style[key] = value
@tanepiper
Copy link
Author

Usage

cssTo querySelector('#foo'), {
  opacity: 0
}, 1000, 'ease-out', ->
  console.log 'complete!!'

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