-
Notifications
You must be signed in to change notification settings - Fork 265
/
Copy pathqueue.xml
204 lines (201 loc) · 6.3 KB
/
queue.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?xml version="1.0"?>
<entries>
<desc>Show or manipulate the queue of functions to be executed on the matched elements.</desc>
<entry type="method" name="queue" return="Array">
<title>.queue()</title>
<signature>
<added>1.2</added>
<argument name="queueName" optional="true" type="String">
<desc>A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.</desc>
</argument>
</signature>
<desc>Show the queue of functions to be executed on the matched elements.</desc>
<longdesc/>
<example>
<desc>Show the length of the queue.</desc>
<code><![CDATA[
var div = $( "div" );
function runIt() {
div
.show( "slow" )
.animate({ left: "+=200" }, 2000 )
.slideToggle( 1000 )
.slideToggle( "fast" )
.animate({ left: "-=200" }, 1500 )
.hide( "slow" )
.show( 1200 )
.slideUp( "normal", runIt );
}
function showIt() {
var n = div.queue( "fx" );
$( "span" ).text( n.length );
setTimeout( showIt, 100 );
}
runIt();
showIt();
]]></code>
<css><![CDATA[
div {
margin: 3px;
width: 40px;
height: 40px;
position: absolute;
left: 0px;
top: 60px;
background: green;
display: none;
}
div.newcolor {
background: blue;
}
p {
color: red;
}
]]></css>
<html><![CDATA[
<p>The queue length is: <span></span></p>
<div></div>
]]></html>
</example>
<category slug="effects/custom-effects"/>
<category slug="data"/>
<category slug="utilities"/>
<category slug="version/1.2"/>
</entry>
<entry type="method" name="queue" return="jQuery">
<signature>
<added>1.2</added>
<argument name="queueName" optional="true" type="String">
<desc>A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.</desc>
</argument>
<argument name="newQueue" type="Array">
<desc>An array of functions to replace the current queue contents.</desc>
</argument>
</signature>
<signature>
<added>1.2</added>
<argument name="queueName" optional="true" type="String">
<desc>A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.</desc>
</argument>
<argument name="callback" type="Function">
<argument name="next" type="Function" />
<desc>The new function to add to the queue, with a function to call that will dequeue the next item.</desc>
</argument>
</signature>
<desc>Manipulate the queue of functions to be executed, once for each matched element.</desc>
<longdesc>
<p>Every element can have one to many queues of functions attached to it by jQuery. In most applications, only one queue (called <code>fx</code>) is used. Queues allow a sequence of actions to be called on an element asynchronously, without halting program execution. The typical example of this is calling multiple animation methods on an element. For example:</p>
<pre><code>
$( "#foo" ).slideUp().fadeIn();
</code></pre>
<p>When this statement is executed, the element begins its sliding animation immediately, but the fading transition is placed on the <code>fx</code> queue to be called only once the sliding transition is complete.</p>
<p>The <code>.queue()</code> method allows us to directly manipulate this queue of functions. Calling <code>.queue()</code> with a callback is particularly useful; it allows us to place a new function at the end of the queue. The callback function is executed once for each element in the jQuery set.</p>
<p>This feature is similar to providing a callback function with an animation method, but does not require the callback to be given at the time the animation is performed.</p>
<pre><code>
$( "#foo" ).slideUp();
$( "#foo" ).queue(function() {
alert( "Animation complete." );
$( this ).dequeue();
});
</code></pre>
<p>This is equivalent to:</p>
<pre><code>
$( "#foo" ).slideUp(function() {
alert( "Animation complete." );
});
</code></pre>
<p>Note that when adding a function with <code>.queue()</code>, we should ensure that <code>.dequeue()</code> is eventually called so that the next function in line executes.</p>
<p><strong>As of jQuery 1.4</strong>, the function that's called is passed another function as the first argument. When called, this automatically dequeues the next item and keeps the queue moving. We use it as follows:</p>
<pre><code>
$( "#test" ).queue(function( next ) {
// Do some stuff...
next();
});
</code></pre>
</longdesc>
<example>
<desc>Queue a custom function.</desc>
<code><![CDATA[
$( document.body ).on( "click", function() {
$( "div" )
.show( "slow" )
.animate( { left: "+=200" }, 2000 )
.queue(function() {
$( this ).addClass( "newcolor" ).dequeue();
})
.animate( { left: "-=200" }, 500 )
.queue(function() {
$( this ).removeClass( "newcolor" ).dequeue();
} )
.slideUp();
} );
]]></code>
<css><![CDATA[
div {
margin: 3px;
width: 40px;
height: 40px;
position: absolute;
left: 0px;
top: 30px;
background: green;
display: none;
}
div.newcolor {
background: blue;
}
]]></css>
<html><![CDATA[
Click here...
<div></div>
]]></html>
</example>
<example>
<desc>Set a queue array to delete the queue.</desc>
<code><![CDATA[
$( "#start" ).on( "click", function() {
$( "div" )
.show( "slow" )
.animate({ left: "+=200" }, 5000 )
.queue(function() {
$( this ).addClass( "newcolor" ).dequeue();
})
.animate({ left: '-=200' }, 1500 )
.queue(function() {
$( this ).removeClass( "newcolor" ).dequeue();
})
.slideUp();
});
$( "#stop" ).on( "click", function() {
$( "div" )
.queue( "fx", [] )
.stop();
});
]]></code>
<css><![CDATA[
div {
margin: 3px;
width: 40px;
height: 40px;
position: absolute;
left: 0px;
top: 30px;
background: green;
display: none;
}
div.newcolor {
background: blue;
}
]]></css>
<html><![CDATA[
<button id="start">Start</button>
<button id="stop">Stop</button>
<div></div>
]]></html>
</example>
<category slug="effects/custom-effects"/>
<category slug="data"/>
<category slug="utilities"/>
<category slug="version/1.2"/>
</entry>
</entries>