码迷,mamicode.com
首页 > Web开发 > 详细

CSS3中动画结束,动画开始事件

时间:2015-01-13 23:02:57      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:

<script type="text/javascript">
var UI = $.AMUI || {};
        var $win = $(window);
        var doc = window.document;
UI.support = {};
    //根据不同浏览器注入不同事件
        UI.support.transition = (function() {
          var transitionEnd = (function() {
            // https://developer.mozilla.org/en-US/docs/Web/Events/transitionend#Browser_compatibility
            var element = doc.body || doc.documentElement;
            var transEndEventNames = {
              WebkitTransition: ‘webkitTransitionEnd‘,
              MozTransition: ‘transitionend‘,
              OTransition: ‘oTransitionEnd otransitionend‘,
              transition: ‘transitionend‘
            };

            for (var name in transEndEventNames) {
              if (element.style[name] !== undefined) {
                return transEndEventNames[name];
              }
            }
          })();

          return transitionEnd && {
            end: transitionEnd
          };
        })();

        UI.support.animation = (function() {
          var animationEnd = (function() {
            var element = doc.body || doc.documentElement;
            var animEndEventNames = {
              WebkitAnimation: ‘webkitAnimationEnd‘,
              MozAnimation: ‘animationend‘,
              OAnimation: ‘oAnimationEnd oanimationend‘,
              animation: ‘animationend‘
            };

            for (var name in animEndEventNames) {
              if (element.style[name] !== undefined) {
                return animEndEventNames[name];
              }
            }
          })();

          return animationEnd && {
            end: animationEnd
          };
        })();
          $.fn.emulateTransitionEnd = function(duration) {
          var called = false;
          var $el = this;

          $(this).one(UI.support.transition.end, function() {
            called = true;
          });

          var callback = function() {
            if (!called) {
              $($el).trigger(UI.support.transition.end);
            }
            $el.transitionEndTimmer = undefined;
          };
          this.transitionEndTimmer = setTimeout(callback, duration);
          return this;
        };
//过度结束执行的回调 $.fn.transitionEnd
= function(callback) { var endEvent = UI.support.transition.end; var dom = this; function fireCallBack(e) { callback.call(this, e); endEvent && dom.off(endEvent, fireCallBack); } if (callback && endEvent) { dom.on(endEvent, fireCallBack); } return this; }; </script>

 

CSS3中动画结束,动画开始事件

标签:

原文地址:http://www.cnblogs.com/mmdrs/p/4222617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!