Skip to content

Commit b354826

Browse files
Niloth-pdev-shetty
authored andcommitted
Create Mouse Chaser
1 parent 34dd4dc commit b354826

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Mouse Chaser</title>
7+
<link rel="stylesheet" href="styles.css">
8+
</head>
9+
<body>
10+
<div class="mover" onmouseover="moverHandler()" id="catch">
11+
<p>Catch me if you can</p>
12+
</div>
13+
<script src="script.js"></script>
14+
</body>
15+
</html>

UI Snippets/Mouse Chaser/script.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const moverHandler = () => {
2+
let moverEle = document.getElementsByClassName("mover")[0];
3+
4+
let maxX = window.innerWidth - moverEle.clientWidth;
5+
let maxY = window.innerHeight - moverEle.clientHeight;
6+
7+
let randomX = Math.random() * maxX;
8+
let randomY = Math.random() * maxY;
9+
10+
randomX = Math.min(randomX, maxX);
11+
randomY = Math.min(randomY, maxY);
12+
13+
moverEle.style.transform = `translate(${randomX}px, ${randomY}px)`;
14+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.mover {
2+
background-color: lightskyblue;
3+
color: black;
4+
display: inline-block;
5+
padding: 0px 20px;
6+
margin: 20px;
7+
font-family: "Arial";
8+
font-size: large;
9+
position: relative;
10+
}

0 commit comments

Comments
 (0)