-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-animate.html
96 lines (91 loc) · 2.95 KB
/
jquery-animate.html
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
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js" integrity="sha256-DI6NdAhhFRnO2k51mumYeDShet3I8AKCQf/tf7ARNhI=" crossorigin="anonymous"></script>
<style type="text/css">
#the-box{
width: 200px;
height: 200px;
background-color: cyan;
border: 3px solid black;
text-align: center;
position: relative;
}
#msg{
border-radius: 5px;
background-color: #4cc94e;
width: 100%;
height: 20px;
padding:10px 0;
text-align: center;
font-weight: bolder;
position: absolute;
bottom: 0;
}
.button {
background-color: #008CBA;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
</style>
</head>
<body>
<h1>jQuery Animate</h1>
<button class="button" id="animate">Animate</button>
<br>
<br>
<div id="the-box">The Box content</div>
<p id="msg">Animation completed!</p>
<script type="text/javascript">
$(document).ready(function (){
'use strict';
//It's always a best practice to save the element in a jQuery var starting with a $ sign
var $box = $('#the-box');
var $btn = $('#animate');
var $msg = $('#msg');
$msg.hide();
//Create an eventListener for the button and calls a function with the animation
$btn.click(function(e){
$msg.fadeOut();
animateBox($box);
animateBoxStack();
$(this).attr('disabled','disabled');
});
//Animates the box within a JSON
function animateBox($el){
$el.animate({
left: "+=30px",
top: "+=50px",
borderRadius: "40px",
transform: "rotate(360deg)"
// height: "toggle"
// opacity:"toggle"
}, 1000, function(){
//callback function procedure
$msg.fadeIn();
$btn.removeAttr('disabled');
});
}
//Animates the box within a JSON
function animateBoxStack(){
$box.animate({
left: "+=10px",
top: "+=10px"
}, 1000).animate({
//Note: this css property required jQuery UI library
backgroundColor: "red"
},1000).animate({
fontSize: '+=1em'
}, 1000);
}
});
</script>
</body>
</html>