forked from danielscarvalho/FTT-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaulajs15.html
More file actions
49 lines (44 loc) · 1.09 KB
/
Copy pathaulajs15.html
File metadata and controls
49 lines (44 loc) · 1.09 KB
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
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Aula 15</title>
<style>
.container {
width: 400px;
height: 400px;
position: relative;
background: lightgray;
}
.box {
width: 50px;
height: 50px;
position: absolute;
background-color: red;
}
</style>
<script>
function animação() {
let box = document.getElementById("box");
let pos = 0;
let id = setInterval(frame, 5);
function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
box.style.top = pos + "px";
box.style.left = pos + "px";
}
}
}
</script>
</head>
<body>
<h1>JavaScript Aula 15</h1>
<h2>Animação via JavaScript</h2>
<p><button onclick="animação()">Animação</button></p>
<div class="container">
<div id="box" class="box"></div>
</div>
</body>
</html>