1
+ <!doctype html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 " />
5
+
6
+ < title >
7
+ Stop() vs. Finish() In jQuery
8
+ </ title >
9
+
10
+ < style type ="text/css ">
11
+
12
+ div .box {
13
+ background-color : # FAFAFA ;
14
+ border : 1px solid # CCCCCC ;
15
+ height : 50px ;
16
+ line-height : 50px ;
17
+ overflow : hidden ;
18
+ width : 0px ;
19
+ }
20
+
21
+ form {
22
+ margin-bottom : 16px ;
23
+ }
24
+
25
+ </ style >
26
+ </ head >
27
+ < body >
28
+
29
+ < h1 >
30
+ Stop() vs. Finish() In jQuery
31
+ </ h1 >
32
+
33
+ < form action ="# ">
34
+ < input type ="button " value ="Reset " class ="reset " />
35
+ < input type ="button " value ="Start " class ="start " />
36
+ < input type ="button " value ="Halt " class ="halt " />
37
+ </ form >
38
+
39
+ < div class ="box box1 ">
40
+ Stop()
41
+ </ div >
42
+
43
+ < br />
44
+
45
+ < div class ="box box2 ">
46
+ Finish()
47
+ </ div >
48
+
49
+
50
+ <!-- Load scripts. -->
51
+ < script type ="text/javascript " src ="../../vendor/jquery/jquery-2.0.3.min.js "> </ script >
52
+ < script type ="text/javascript ">
53
+
54
+ // Cache our DOM elements like good citizens.
55
+ var dom = {
56
+ reset : $ ( "input.reset" ) ,
57
+ start : $ ( "input.start" ) ,
58
+ halt : $ ( "input.halt" ) ,
59
+ box1 : $ ( "div.box1" ) ,
60
+ box2 : $ ( "div.box2" )
61
+ } ;
62
+
63
+ // Reset the demo by quitting all animations and manually
64
+ // setting the widths.
65
+ dom . reset . click (
66
+ function ( event ) {
67
+
68
+ dom . box1 . add ( dom . box2 )
69
+ . stop ( true , true )
70
+ . width ( 0 )
71
+ ;
72
+
73
+ }
74
+ ) ;
75
+
76
+ // Start animations on both elements. The animations will
77
+ // include a slide-out followed by a slide-in of each element.
78
+ // Meaning, there are two different animations in the queue at
79
+ // the start of the experiment.
80
+ dom . start . click (
81
+ function ( event ) {
82
+
83
+ dom . box1 . add ( dom . box2 )
84
+ . animate ( { width : "400px" } , 3000 )
85
+ . animate ( { width : "0px" } , 2000 )
86
+ ;
87
+
88
+ }
89
+ ) ;
90
+
91
+ // Stop both animations.
92
+ dom . halt . click (
93
+ function ( event ) {
94
+
95
+ // True ( clear queue, jump to end ).
96
+ dom . box1 . stop ( true , true ) ;
97
+
98
+ dom . box2 . finish ( ) ;
99
+
100
+ }
101
+ ) ;
102
+
103
+ </ script >
104
+
105
+ </ body >
106
+ </ html >
0 commit comments