jQuery 封装队列 .Queue()入队 出队

队列的入队与出对

    jQuery.prototype.Queue = function(){              //type 起的队列名字   handle  队列内容   type,handle
        var queueObj = this;                          //jQuery对象
        var queueName = arguments[0] || 'fx';         //传参第一位  队列起名
        var addFunc = arguments[1] || null;          //传参第二位  队列内容
        var len = arguments.length;

        if(len == 1){
            return queueObj[0][queueName];     //有名字的话把名字传进来
        }
        //判断 dome对象有么有名字  没有名字填入名字有名字把内容填进去
        queueObj[0][queueName] == undefined ? queueObj[0][queueName] = [addFunc] : queueObj[0][queueName].push(addFunc);
        return this;
    }
    

    jQuery.prototype.Dequeue = function(type){
        var self = this;                        //外部jq对象
        var queueName = arguments[0] || 'fx';   //传进来的队列名
        var queueArr = this.Queue(queueName);   //把这个队列拿出来
        var currFunc = queueArr.shift();        //把队列里的值删掉
        //判断队列里有没有值了  没有值就成为递归出口
        if(currFunc == undefined){
            return;
        }  
        var next = function() {            //巧妙用next参数进行下一次出队
            self.Dequeuee(queueName);
        }
        currFunc(next);
        return this;
    }

猜你喜欢

转载自blog.csdn.net/weixin_44185579/article/details/88737961