-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (23 loc) · 827 Bytes
/
script.js
File metadata and controls
27 lines (23 loc) · 827 Bytes
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
var rocket = document.querySelector("i");
rocket.addEventListener("mouseenter", () => {
rocket.classList.toggle("fa-rotate");
var vw = document.documentElement.clientWidth;
var vh = document.documentElement.clientHeight;
var chgLeft = Math.floor(Math.random() * (vw / 2));
var chgTop = Math.floor(Math.random() * (vh / 2));
//setting up the random position for mobile view
if (vw <= 450 || vh <= 800) {
vw = vw - chgLeft - 200;
vh = vh - chgTop - 300;
} else { //setting up the random position for pc view
vw = vw - chgLeft - 500;
vh = vh - chgTop - 400;
}
if (vw <= -20 || vh <=0) { //avoiding the rcoket to go beyond the screen dimensions
vw = 20;
vh = 10;
}
//setting the final vh & vw to the rocket
rocket.style.top = `${vh}px`;
rocket.style.left = `${vw}px`;
});