瀏覽代碼

Fade animation included and prevent routering if something is animating

piniphone 13 年之前
父節點
當前提交
9a7d0006bc
共有 3 個文件被更改,包括 37 次插入3 次删除
  1. 2 2
      example/navigation.html
  2. 4 1
      src/modules/Lungo.Router.coffee
  3. 31 0
      src/stylesheets/lungo.animation.fade.styl

文件差異過大導致無法顯示
+ 2 - 2
example/navigation.html


+ 4 - 1
src/modules/Lungo.Router.coffee

@@ -18,12 +18,14 @@ Lungo.Router = do (lng = Lungo) ->
   _inPage             = undefined
   _animating          = false
 
+
   ###
   Navigate to a <section>.
   @method   section
   @param    {string} Id of the <section>
   ###
   section = (section_id) ->
+    if _animating then return
     _outPage = lng.Element.Cache.section
     if _notCurrentTarget(_outPage, section_id)
       query = C.ELEMENT.SECTION + HASHTAG + section_id
@@ -47,6 +49,7 @@ Lungo.Router = do (lng = Lungo) ->
   @method   back
   ###
   back = ->
+    if _animating then return
     do _removeLast
     _outPage = lng.Element.Cache.section
     query = C.ELEMENT.SECTION + HASHTAG + history()
@@ -122,8 +125,8 @@ Lungo.Router = do (lng = Lungo) ->
   _removeLast = -> _history.length -= 1
 
   _bindAnimationEnd = ->
-    document.addEventListener(ev, _transitionEnd) for ev in ANIMATIONEND_EVENTS
     _animating = true
+    document.addEventListener(ev, _transitionEnd) for ev in ANIMATIONEND_EVENTS
 
   _unbindAnimationEnd = ->
     document.removeEventListener(ev, _transitionEnd) for ev in ANIMATIONEND_EVENTS

+ 31 - 0
src/stylesheets/lungo.animation.fade.styl

@@ -0,0 +1,31 @@
+@import "__init.styl"
+
+.fadeIn
+  vendor(animation, fadeIn TRANSITION_TIME ease both)
+.fadeOut
+  vendor(animation, fadeOut TRANSITION_TIME ease both)
+.fadeInBack
+  vendor(animation, fadeInBack TRANSITION_TIME ease both)
+.fadeOutBack
+  vendor(animation, fadeOutBack TRANSITION_TIME ease both)
+
+
+@keyframes fadeIn
+  from {
+    opacity: 0
+  }
+
+@keyframes fadeOut
+  to {
+    opacity: 1
+  }
+
+@keyframes fadeInBack
+  from {
+    opacity: 0
+  }
+
+@keyframes fadeOutBack
+  to {
+    opacity: 0
+  }