zoukankan      html  css  js  c++  java
  • Animation

    Animation

    (function ($) {
        function active(target, index) {
            var actions = $(target).data('actions');
            if (index < actions.length) {
                var callee = arguments.callee;
                var action = actions[index];
                if (!$(target).data('stop')) {
                    if (action.action(action.context) !== false) {
                        var timer = setTimeout(function () { callee(target, index + 1); clearTimeout(timer); }, action.time);
                    }
                    $(target).data('curIndex', index);
                }
            }
        }
        function Animation(actions) {
            if (actions) {
                $(this).data('actions', actions);
            }
            else {
                $(this).data('actions', []);
            }
            $(this).data('curIndex', 0);
            this.addAction = function (action, context, time) {
                $(this).data('actions').push({ action: action, context: context, time: time });
                return this;
            }
            this.removeAction = function (action) {
                var actions = $(this).data('actions');
                $(actions).each(function (i, v) {
                    if (v.action == action||v==action) {
                        actions.splice(i, 1);
                        return false;
                    }
                });
                return this;
            }
            this.start = function () {
                $(this).data('stop',false);
                active(this, 0);
                return this;
            }
            this.stop = function () {
                $(this).data('stop', true);
                return this;
            }
            this.goon = function () {
                $(this).data('stop', false);
                active(this, $(this).data('curIndex') + 1);
                return this;
            }
        }
        $.Animation = function () {
            return new Animation();
        }
    })(jQuery);

    Demo:

    <html>
    <head>
        <title>animation</title>
        <script src="~/Script/jquery-1.11.3.js"></script>
        <script src="~/Script/jAnimation.js"></script></head>
        <script>
       $.Animation().addAction(function (context) { console.log(context); }, 1, 2000).addAction(function (context) {console.log(context);}, 2, 4000).addAction(function (context) {console.log(context);}, 3, 3000).start(); 
       </script>
    <body>
    </body>
    </
    html>
  • 相关阅读:
    php反射类 ReflectionClass
    大写中文数字-財务
    Cookie/Session机制具体解释
    具体解释VB中连接access数据库的几种方法
    Hibernate Criterion
    hdu1151 Air Raid,DAG图的最小路径覆盖
    【收藏】十大Webserver漏洞扫描工具
    美国地名大全(美国城市名称英文、中文)
    图像切割之(五)活动轮廓模型之Snake模型简单介绍
    数据库索引的作用和长处缺点
  • 原文地址:https://www.cnblogs.com/kingge/p/4925211.html
Copyright © 2011-2022 走看看