jQuery 第五章 实例方法 详解内置队列queue() dequeue() 方法
.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() 方法的更多相关文章
- jQuery 第五章 实例方法 详解动画之animate()方法
.animate() .stop() .finish() ------------------------------------------------------------------- ...
- jQuery 第五章 实例方法 事件
.on() .one() .off() .trigger() .click / keydown / mouseenter ... .hover() ----------------------- ...
- 搜索引擎算法研究专题五:TF-IDF详解
搜索引擎算法研究专题五:TF-IDF详解 2017年12月19日 ⁄ 搜索技术 ⁄ 共 1396字 ⁄ 字号 小 中 大 ⁄ 评论关闭 TF-IDF(term frequency–inverse ...
- jquery $.trim()去除字符串空格详解
jquery $.trim()去除字符串空格详解 语法 jQuery.trim()函数用于去除字符串两端的空白字符. 作用 该函数可以去除字符串开始和末尾两端的空白字符(直到遇到第一个非空白字符串为止 ...
- redis 五种数据结构详解(string,list,set,zset,hash)
redis 五种数据结构详解(string,list,set,zset,hash) Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存 ...
- Android Studio系列教程五--Gradle命令详解与导入第三方包
Android Studio系列教程五--Gradle命令详解与导入第三方包 2015 年 01 月 05 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://s ...
- redis 五种数据结构详解(string,list,set,zset,hash),各种问题综合
redis 五种数据结构详解(string,list,set,zset,hash) https://www.cnblogs.com/sdgf/p/6244937.html redis 与 spring ...
- 【Redis】redis 五种数据结构详解(string,list,set,zset,hash)
redis 五种数据结构详解(string,list,set,zset,hash) Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存 ...
- rabbitmq五种模式详解(含实现代码)
一.五种模式详解 1.简单模式(Queue模式) 当生产端发送消息到交换机,交换机根据消息属性发送到队列,消费者监听绑定队列实现消息的接收和消费逻辑编写.简单模式下,强调的一个队列queue只被一个消 ...
随机推荐
- 三种方式获取SSMS连接密码
内网渗透是有的时候会遇到对方SSMS没断开连接正连着别的机器的mssql此时有两种方法可以获取sa密码 当密码强度较弱时可以使用第一只方式,第一种方式解不开的情况下可以使用后面二种方式 1.直接查询s ...
- 数位dp(贴一个模板=。=)
emmmm,之前看到大佬的博客感觉这个模板挺有用的,就贴了一个= = 然后解释什么的都有了就...... 数位dp一般应用于: 求出在给定区间[A,B]内,符合条件P(i)的数i的个数. 条件P(i) ...
- D. Concatenated Multiples 解析(思維)
Codeforce 1029 D. Concatenated Multiples 解析(思維) 今天我們來看看CF1029D 題目連結 題目 給你一個序列\(a\)和一個數字\(k\),求有幾種ind ...
- C#基础访问修饰符概述
前言: 在编写面向对象语言时我们时长离不开相关类型和成员的相关访问性,而访问性的关键则是取决于访问修饰符的声明,其作用是用于指定类型或成员的可访问性. 访问修饰符的六种可访问性级别: public:共 ...
- 导入tensorflow.出现importError: DLL load failed: 找不到指定的模块。
导入tensorflow.出现importError: DLL load failed: 找不到指定的模块. 原因 这是由于windows上没有相应的动态链接库导致的,tensorflow依赖很多c+ ...
- html关键字高亮
/** * @id 父节点id * @key 关键字 */ function keyLight(id, key, bgColor){ var oDiv = document.getElementByI ...
- MySQL主主数据同步
环境 操作系统版本:CentOS 6.5 64位MySQL版本:mysql5.6节点1IP:192.168.0.235 主机名:taojiang1-mysql-01节点2IP:192.168.0.23 ...
- AC86U kx上网
AC86U收到很久了,为了能够kx上网免不了一番折腾. 准备 U盘一个, 读写速度要大于30M/s, 用于制作虚拟内存 步骤大致如下: 1.下载koolshare固件 我这里下载的是官改固件:http ...
- ajax传值出现乱码问题
第一种:前台传值到后台,浏览器控制台打印正常,controller接收后成了乱码. 后台controller层加上两行转换代码 name=URLDecoder.decode(name,"ut ...
- SQL2005中清空操作日志的语句(SQL2008有所不同)
方法一(我常用的): backup transaction 库名 with no_log go DBCC SHRINKDATABASE(库名) go 在VS中调用语句: string sb = &qu ...