/
animate_exercise.html
83 lines (79 loc) · 2.33 KB
/
animate_exercise.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
<!DOCTYPE html>
<html>
<head>
<title>Animate</title>
<style>
html, body {
margin: 0px;
padding: 0;
}
#btn-animate {
margin: 15px;
}
#animate-box {
background-color: #000033;
height: 250px;
margin: 15px;
position: relative;
width: 250px;
}
</style>
</head>
<body>
<p>
<button id="btn-move">Move It</button>
<button id="btn-scale">Scale It</button>
<button id="btn-hide">Hide It</button>
<button id="btn-show">Show It</button>
<button id="btn-all">Animate All</button>
</p>
<div id="animate-box"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
"use strict";
// TODO: "Move It" should move the box 100 pixels to the left
$('#btn-move').on('click', function () {
$('#animate-box').animate({
left: '+=100px'
});
});
// TODO: "Scale It" should expand the box width by 50%
$('#btn-scale').on('click', function () {
$('#animate-box').animate({
width: '+=50%'
});
});
// TODO: "Hide It" should use opacity to make the box invisible
$('#btn-hide').on('click', function () {
$('#animate-box').animate({
opacity: '-=0.2'
});
});
// TODO: "Show It" should make the box appear
$('#btn-show').on('click', function () {
$('#animate-box').animate({
opacity: '+=0.2'
});
});
// TODO: "Animate All" should use an animation stack to:
$('#btn-all').on('click', function () {
$('#animate-box').animate({
width: '+=50%',
left: '+=100px'
},1000).animate({
opacity: '0'
},2000).animate({
opacity: '1'
},2000).animate({
width: '250px',
left: '0px'
});
});
// 1) Move and scale the box simultaneously
// 2) Hide the box
// 3) Reset the box back to its original position and opacity
});
</script>
</body>
</html>