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>
  • 相关阅读:
    MiniUI破解方法
    mysql [索引优化] -- in or替换为union all
    MySQL匹配指定字符串的查询
    MySQL优化之like关键字
    Java身份证归属地目录树
    JS数字指定长度不足前补零的实现
    jQuery Distpicker插件 省市区三级联动 动态赋值修改地址
    JS 正则表达式从地址中提取省市县
    Eclipse/myEclipse 代码提示/自动提示/自动完成设置
    Spring Mvc配置多视图
  • 原文地址:https://www.cnblogs.com/kingge/p/4925211.html
Copyright © 2011-2022 走看看