-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjsAnimations.html
More file actions
41 lines (41 loc) · 1.05 KB
/
Copy pathjsAnimations.html
File metadata and controls
41 lines (41 loc) · 1.05 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
<!DOCTYPE html>
<html>
<style>
#container {
width: 400px;
height: 400px;
border: 1px solid;
position: relative;
}
#square {
width: 50px;
height: 50px;
background-color: red;
position: absolute;
/* left: 350px; */
right: 0;
bottom: 0;
}
</style>
<body>
<div id='container'>
<div id='square'></div>
</div>
<button onclick="animateButton()">Animate</button>
<script>
function animateButton() {
let element = document.getElementById('square')
let pos = 0
let id = setInterval(adjustPosition, 10) // will call adjust position for
//every 10 milli seconds
function adjustPosition() {
if (pos === 350) clearInterval(id)
pos++ // increase the position by 1px for every 10 milli seconds
element.style.right = pos+'px'
element.style.bottom = pos+'px'
// console.log('set interval function')
}
}
</script>
</body>
</html>