-
Notifications
You must be signed in to change notification settings - Fork 843
/
Copy pathjs-transitions.html
64 lines (61 loc) · 1.36 KB
/
js-transitions.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
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>JavaScript transitions demo</title>
<style>
body {
background-color: #fff;
color: #333;
font:
1.2em / 1.5 Helvetica Neue,
Helvetica,
Arial,
sans-serif;
padding: 0;
margin: 0;
}
h1 {
font-size: 1.2em;
}
main {
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
max-width: 660px;
height: 400px;
border: 1px solid #ccc;
padding: 20px;
}
.ball {
border-radius: 25px;
width: 50px;
height: 50px;
background: #c00;
position: absolute;
top: 0;
left: 0;
transition: transform 1s;
}
</style>
</head>
<body>
<main>
<h1>Click anywhere to move the ball</h1>
<div id="foo" class="ball"></div>
</main>
</body>
<script>
var f = document.getElementById("foo");
document.addEventListener(
"click",
function (ev) {
f.style.transform = "translateY(" + (ev.clientY - 25) + "px)";
f.style.transform += "translateX(" + (ev.clientX - 25) + "px)";
},
false,
);
</script>
</html>