-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle.html
51 lines (45 loc) · 1.17 KB
/
circle.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Circle</title>
</head>
<style type="text/css">
#box {
width: 500px;
height: 500px;
background: #CCC;
cursor: move;
}
#box p {
padding-left: 60px;
}
#box #ball {
border-radius: 50px;
width: 50px;
height: 50px;
background: #00c;
position: absolute;
top: 0;
left: 0;
transition: transform 1s;
}
</style>
</head>
<body>
<div id="box">
<p>Click anywhere on the gray area to make the ball follow you</p>
<div id="ball"></div>
</div>
<script type="text/javascript">
var ball = document.getElementById('ball');
var box = document.getElementById('box');
box.addEventListener('click', function (event) {
ball.style.transform = 'translateY(' + (event.clientY - 25) + 'px) ';
ball.style.transform += 'translateX(' + (event.clientX - 25) + 'px)';
});
</script>
</body>
</html>