javascript效果队列(链)

发布于 2024-09-30 04:33:37 字数 950 浏览 2 评论 0原文

我正在为我的工作构建一个动画框架,并且我库存在队列或连锁效果部分,实际上我有这样的东西:

var Fx = {
    animate: function(){...},
    fadeIn: function(){...},
    fadeOut: function(){...}
}

等等等等...所以,实际上我可以这样做:

$('#element').animate({options}).fadeIn({options});

而且效果非常好!但是 fadeIn 和 animate 同时执行,但我想做的是:

$('#element').chain().animate({options}).fadeIn({options});

所以它先执行 animate,然后执行 fadeIn

实际上我有类似的东西:

var Chain = function(element){
 var target = element;
 for (methodName in Fx) {

  (function(methodName) {
    Chain.prototype[methodName] = function() {
     var args = Array.prototype.slice.call(arguments);
    return this;
    };
  })(methodName);
 }
}

Fx.chain = function(element){
  return 
    }

我可以获得所有被调用的方法和那些东西,但我不知道如何将其推送到数组,甚至不知道如何调用第一个方法,因为我试图获取对数组的所有请求,并在每次效果完成时调用它。

我不使用 jQuery,正如我所说,我需要制作一个个性化的框架。

有什么想法吗?谢谢

im building an animation framework for my work, and im stock in the Queue or chain effects part, actually i have something like this:

var Fx = {
    animate: function(){...},
    fadeIn: function(){...},
    fadeOut: function(){...}
}

etc etc... so, actually i can do:

$('#element').animate({options}).fadeIn({options});

and it works excellent! but the fadeIn and the animate execute at the same time but what i want to do, is something like:

$('#element').chain().animate({options}).fadeIn({options});

so it execute the animate first and then the fadeIn

actually i have something like:

var Chain = function(element){
 var target = element;
 for (methodName in Fx) {

  (function(methodName) {
    Chain.prototype[methodName] = function() {
     var args = Array.prototype.slice.call(arguments);
    return this;
    };
  })(methodName);
 }
}

Fx.chain = function(element){
  return 
    }

and i can get all the methods called and that stuff, but i dont know how to push that to an array or even call the first method, because im trying to get all requests to an array and just call it everytime if effects is done.

im not use jQuery, as i said i need to make a personalized framework.

Any idea pleeeasse??! Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞梦里开花 2024-10-07 04:33:37

简单演示

var Fx = {
  animate: function(el, style, duration, after){
    // do animation...
    after();
  },
  fadeIn: function(el, duration, after){
    // do fading ...
    after();
  }, 
  // other effects ...

  chain: function (el) {

    var que = [];
    function callNext() { que.length && que.shift()(); }

    return {
      animate: function(style, duration) {
        que.push(function() {
          Fx.animate(el, style, duration, callNext);
        });
        return this;
      },
      fadeIn: function(duration){
        que.push(function() {
          Fx.fadeIn(el, duration, callNext);
        });
        return this;
      }, // ...
      end: callNext
    };
  }
};

用法

Fx.chain(el).animate("style", 300).fadeIn(600).animate("style2", 900).end();

Simple Demo

var Fx = {
  animate: function(el, style, duration, after){
    // do animation...
    after();
  },
  fadeIn: function(el, duration, after){
    // do fading ...
    after();
  }, 
  // other effects ...

  chain: function (el) {

    var que = [];
    function callNext() { que.length && que.shift()(); }

    return {
      animate: function(style, duration) {
        que.push(function() {
          Fx.animate(el, style, duration, callNext);
        });
        return this;
      },
      fadeIn: function(duration){
        que.push(function() {
          Fx.fadeIn(el, duration, callNext);
        });
        return this;
      }, // ...
      end: callNext
    };
  }
};

Usage

Fx.chain(el).animate("style", 300).fadeIn(600).animate("style2", 900).end();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文