Commits

paulc  committed 96d77de

Add tween method

  • Participants
  • Parent commits 47dc372

Comments (0)

Files changed (1)

     show: () -> @css 'display','block'
     hide: () -> @css 'display','none'
     load: (url) -> ajax('GET',url,(s) => @text s); @
+    tween: (props,ms,f) ->
+        ms = ms ? 500
+        steps = Math.ceil (ms+1)/50
+        r = /([+-]?[0-9\.]+)(.*)/
+        for property,[_start,_end] of props
+            start = parseFloat(([_,_,unit] = r.exec(_start))[1])
+            end = parseFloat(r.exec(_end)[1])
+            for i in [0..steps]
+                val = start + i * (end-start)/steps
+                f = () => @css property,val + unit
+                setTimeout f,i * ms/steps
+        @
     fade: (end,ms) ->
         start = parseFloat(@css("opacity") or 1)
-        end = end ? 1 - start
-        ms = ms ? 500
-        steps = Math.ceil (ms+1)/50
-        setTimeout((() => @css "opacity",start + i * (end-start)/steps),i * ms/steps) for i in [0..steps]
-        @
+        @tween {'opacity':[start,end ? 1 - start]}, ms ? 500
     value: (v) -> @first (e) ->
         if v? then switch e.type
             when 'select-one'