Skip to content

Instantly share code, notes, and snippets.

@imathis
Created December 14, 2012 17:35
Show Gist options
  • Save imathis/4287186 to your computer and use it in GitHub Desktop.
Save imathis/4287186 to your computer and use it in GitHub Desktop.
Handy little jQuery extensions for working with time based class names.
(($) ->
# Add a class until a period of time. Fires a callback when complete
$.fn.addClassUntil = (className, time=400, onComplete = (->true))->
el = this
el.addClass className
setTimeout (-> el.removeClass(className); onComplete()), time
this
# Add a class after a period of time. Fires a callback when complete
$.fn.addClassAfter = (className, time=400, onComplete = (->true))->
el = this
setTimeout (-> el.addClass(className); onComplete()), time
)($)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment