Giter VIP home page Giter VIP logo

bueue.js's Introduction

Bueue.js



  简单的,让函数们乖♂乖♂站好排成一队的js.

Then, how to use it ?

  • 引入js.
<script src='./bueue.min.js' charset='UTF-8'></script>  
  • 对队列进行操作:

    1.顺序添加函数:

    $bueue.c(function);  

    这样,bueue会自动把你的函数加入队列并赋予一个id.

    var a=$bueue.c(function(){
        console.log('This is the 1st item');
        setTimeout(function(){$bueue.next();},2000);
    });
    var b=$bueue.c(function(){
        console.log('This is the 2nd item');
        setTimeout(function(){$bueue.next();},2000);
    });
    var c=$bueue.c(function(){
        console.log('This is the 3rd item');
        setTimeout(function(){$bueue.next();},2000);
    });
    var d=$bueue.c(function(){
        console.log('This is the 4th item');
        setTimeout(function(){$bueue.next();},2000);
    });
    console.log(a+' '+b+' '+c+' '+d);

    输出:0,1,2,3.没错,bueue项目的id是从0开始计的.

    2.啊不想要这个函数待着了,从队列里移除吧!

    $bueue.d(id);  

    id即为顺序添加时返回的值.

    3.队列里空出来一个位置,插入一个函数吧!

    $bueue.e(id,function);  

    这将会在队列中指定id的空位插入一个函数,这里有个小技巧,你需要先删除原有位置上的函数。

    4.让队列开始执行.

    $bueue.start();  

    5.来一发仙人跳跳跃执行~

    $bueue.jump(id);  

    执行这一步后接下来执行的便是编号为id的函数.

    6.执行下一个.

    $bueue.next();  

    这个方法通常在上一个函数的末尾加入,以在上一个函数运行结束时能开始执行下一个.

    7.重置队列.

    $bueue.re();  

    当不带bool值时,这个方法默认是复原id计数,从第一个函数开始执行.

    $bueue.re(true);  

    但是当带上true时会清除队列,一切回到解放前.

    8.打开/关闭DEBUG输出.

    $bueue.de(true/false);  

    输出默认关闭,当开启输出时,控制台会显示队列的情况:

    9.队列状态.

    $bueue.state;

    State:

    • 1 -> 未执行.
    • 2 -> 执行中.
    • 3 -> 执行完毕.

    PS:re()重置后state值会变成1.

Example

var a=$bueue.c(function(){
	console.log('This is the 1st item');
	setTimeout(function(){$bueue.next();},2000);
});
var b=$bueue.c(function(){
	console.log('This is the 2nd item');
	setTimeout(function(){$bueue.next();},2000);
});
var c=$bueue.c(function(){
	console.log('This is the 3rd item');
	setTimeout(function(){$bueue.next();},2000);
});
var d=$bueue.c(function(){
	console.log('This is the 4th item');
	setTimeout(function(){$bueue.next();},2000);
});
$bueue.c(function(){
	console.log('This is the END.');
});

$bueue.start();

输出结果:

This is the 1st item  
This is the 2nd item  
This is the 3rd item  
This is the 4th item  
This is the END.  

bueue.js's People

Contributors

somebottle avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.