.queue()  .dequeue()  .clearQueue()

--------------------------------------------------------------------------

   .queue()

往队列 里面放东西

参数: .queue([queueName], fuc(next))

queueName: 队列名,字符串形式, 默认是 fx 

fuc(next) : 可传函数, 等一系列 值。 他会把你的值, 放到 数组里面。 (next) 如果你函数传了 形参 next ,你可以拿next()在函数里执行,使用方法, 看下面例子  

.queue(queueName):  只传queueName  相当于读取 队列名为queueName  的数组

  .dequeue()

执行队列。

参数: queueName  找到 队列名为 queueName 的数组, 一次一次执行他们  

.dequeue(queueName)

你会发现, 每次都是一个一个拿,好麻烦。 可以利用next 帮你执行下个函数

  .clearQueue()

清空队列

参数, 传入你要清空的 队列名

下面来看下  queue()  和 dequeue 的原理   请看 98 行的 myqueue方法  和 111行的 mydequeue方法

  1 (function(){
2 function jQuery(selector){
3 return new jQuery.prototype.init(selector);
4 }
5 jQuery.prototype.init = function (selector) {
6 this.length = 0;
7 if (selector == null) {
8 return this;
9 }
10 if(typeof selector == 'string' && selector.indexOf('.') != -1 ){
11 var dom = document.getElementsByClassName(selector.slice(1));
12 }else if(typeof selector == 'string' && selector.indexOf('#') != -1 ){
13 var dom = document.getElementById( selector.slice(1) );
14 }else if(typeof selector == 'string'){
15 var dom = document.getElementsByTagName(selector);
16 }
17
18
19 if(selector instanceof Element || dom.length == undefined ){
20 this[0] = dom || selector;
21 this.length ++;
22 }else{
23 for( var i = 0; i < dom.length; i++ ){
24 this[i] = dom[i];
25 }
26 this.length = dom.length;
27 }
28 }
29 jQuery.prototype.pushStack = function (dom) {
30 if (dom.constructor != jQuery) {
31 dom = jQuery(dom);
32 }
33 dom.prevObj = this;
34 return dom;
35 }
36 jQuery.prototype.css = function(config){
37 for(var i = 0; i < this.length; i++){
38 for(var prop in config){
39 this[i].style[prop] = config[prop];
40 }
41 }
42 return this;
43 }
44
45 jQuery.prototype.get = function(num) {
46 return num == null ? [].slice.call(this, 0) : (num < 0 ? this[num + this.length] : this[num]);
47 }
48
49 jQuery.prototype.eq = function (num) {
50 var dom = num == null ? null : (num < 0 ? this[num + this.length] : this[num]);
51 return this.pushStack(dom);
52 }
53
54 jQuery.prototype.add = function (selector) {
55 var baseObj = this;
56 var curObj = jQuery(selector);
57 var newObj = jQuery();
58
59 for (var i = 0; i < baseObj.length; i++) {
60 newObj[newObj.length++] = baseObj[i];
61 }
62 for (var i = 0; i < curObj.length; i++) {
63 newObj[newObj.length++] = curObj[i];
64 }
65
66 return this.pushStack(newObj);
67 }
68
69 jQuery.prototype.end = function () {
70 return this.prevObj;
71 }
72
73 jQuery.prototype.myOn = function(type, func){
74 for(var i = 0; i < this.length; i ++){
75 if(!this[i].cacheEvent){
76 this[i].cacheEvent = {}
77 }
78 if(!this[i].cacheEvent[type]){
79 this[i].cacheEvent[type] = [func];
80 }else{
81 this[i].cacheEvent[type].push(func);
82 }
83 }
84 }
85
86 jQuery.prototype.myTrigger = function(type){
87 var params = arguments.length > 1 ? [].slice.call(arguments, 1) : [];
88 var self = this;
89 for(var i = 0; i < this.length; i ++){
90 if(this[i].cacheEvent[type]){
91 this[i].cacheEvent[type].forEach(function(ele, index){
92 ele.apply(self, params);
93 })
94 }
95 }
96 }
97
98 jQuery.prototype.myqueue = function(){
99 var myqueueName = arguments[0] || 'fx'; //看他 有没有传参数,有的话用, 没有的话用 fx fx是animate的
100 var myqueueFun = arguments[1] || null;
101
102 if(arguments.length == 1){ //如果传了一个参数, 说明你要的是 读取
103 return this[0][myqueueName];
104 }
105 //如果过了上面那个if 说明你有两个参数,要添加 ↓ 添加 队列 , 添加到dom 身上
106 this[0][myqueueName] == undefined ? this[0][myqueueName] = myqueueFun : this[0][myqueueName].push(myqueueFun);
107
108 return this;
109 }
110
111 jQuery.prototype.mydequeue = function(type){
112 var self = this; // 这里的this 是为了给next 使用, 因为 next 是在外部执行, this 指向的是window
113 var mydequeueName = type || 'fx';
114 var myqueueArr = this.myqueue(mydequeueName); //使用myqueue 方法,读取 数组,
115 var currFun = myqueueArr.shift(); // 把数组的 第一个 剪切 出来
116
117 if(currFun == undefined){ // 递归的出口
118 return;
119 }
120 var next = function(){
121 self.mydequeue(mydequeueName); //如果函数形参有传 next 那么就递归。
122 }
123 currFun(next);
124
125 return this;
126 }
127
128 jQuery.prototype.init.prototype = jQuery.prototype;
129
130 window.$ = window.jQuery = jQuery;
131 })()

jQuery 第五章 实例方法 详解内置队列queue() dequeue() 方法的更多相关文章

  1. jQuery 第五章 实例方法 详解动画之animate()方法

    .animate()   .stop()   .finish() ------------------------------------------------------------------- ...

  2. jQuery 第五章 实例方法 事件

    .on() .one() .off() .trigger() .click / keydown / mouseenter ...    .hover() ----------------------- ...

  3. 搜索引擎算法研究专题五:TF-IDF详解

    搜索引擎算法研究专题五:TF-IDF详解 2017年12月19日 ⁄ 搜索技术 ⁄ 共 1396字 ⁄ 字号 小 中 大 ⁄ 评论关闭   TF-IDF(term frequency–inverse ...

  4. jquery $.trim()去除字符串空格详解

    jquery $.trim()去除字符串空格详解 语法 jQuery.trim()函数用于去除字符串两端的空白字符. 作用 该函数可以去除字符串开始和末尾两端的空白字符(直到遇到第一个非空白字符串为止 ...

  5. redis 五种数据结构详解(string,list,set,zset,hash)

    redis 五种数据结构详解(string,list,set,zset,hash) Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存 ...

  6. Android Studio系列教程五--Gradle命令详解与导入第三方包

    Android Studio系列教程五--Gradle命令详解与导入第三方包 2015 年 01 月 05 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://s ...

  7. redis 五种数据结构详解(string,list,set,zset,hash),各种问题综合

    redis 五种数据结构详解(string,list,set,zset,hash) https://www.cnblogs.com/sdgf/p/6244937.html redis 与 spring ...

  8. 【Redis】redis 五种数据结构详解(string,list,set,zset,hash)

    redis 五种数据结构详解(string,list,set,zset,hash) Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存 ...

  9. rabbitmq五种模式详解(含实现代码)

    一.五种模式详解 1.简单模式(Queue模式) 当生产端发送消息到交换机,交换机根据消息属性发送到队列,消费者监听绑定队列实现消息的接收和消费逻辑编写.简单模式下,强调的一个队列queue只被一个消 ...

随机推荐

  1. Glide缓存图片

    是用Glide加载网络图片可以自动缓存到磁盘 添加依赖: implementation 'com.github.bumptech.glide:glide:4.9.0' implementation ' ...

  2. Windows2008R2+ IIS7.5+php+mysql 搭建教程

    Windows2008R2+ IIS7.5+php+mysql 搭建教程 1. IIS7.5安装安装角色时候因为 Fastcgi 的需要, aspnet 和 asp 都要选装. 我为了方便,所有的除 ...

  3. Spring入门-------------1

    Spring是一个开源框架,为简化企业级应用开发而生,使用Spring可以使简单的JavaBean 实现以前只有EJB才能实现的功能.Spring 是一个IOC和Aop容器框架. 特性: 轻量级:Sp ...

  4. CF1336 Linova and Kingdom

    题面 给定 n 个节点的有根树,根是 1 号节点. 你可以选择 k 个节点将其设置为工业城市,其余设置为旅游城市. 对于一个工业城市,定义它的幸福值为工业城市到根的路径经过的旅游城市的数量. 你需要求 ...

  5. python爬虫爬取策略

    爬取策略 关注公众号"轻松学编程"了解更多. 在爬虫系统中,待抓取URL队列是很重要的一部分.待抓取URL队列中的URL以什么样的顺序排列也是一个很重要的问题,因为这涉及到先抓取那 ...

  6. [python学习手册-笔记]001.python前言

    001.python前言 ❝ 本系列文章是我个人学习<python学习手册(第五版)>的学习笔记,其中大部分内容为该书的总结和个人理解,小部分内容为相关知识点的扩展. 非商业用途转载请注明 ...

  7. Android Google官方文档解析之——Device Compatibility

    Android is designed to run on many different types of devices, from phones to tablets and television ...

  8. Qt基础之菜单栏

    本篇介绍Qt菜单栏相关操作,分为三部分:1.菜单栏相关的类介绍:2.系统菜单的生成和响应:3.弹出菜单的生成和响应:菜单栏通常只有以QMainWindow为基类的程序中才用到,以QWidget为基类的 ...

  9. 为什么人们总是认为epoll 效率比select高!!!!!!

    今天看公司代码时,发现代码里面使用的事清一色的代码使用epoll, 所以就得说一说了:宏观看一看epoll 和select的实现: select原理概述 调用select时,会发生以下事情: 从用户空 ...

  10. 451. Sort Characters By Frequency(桶排序)

    Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...