-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (49 loc) · 1.81 KB
/
script.js
File metadata and controls
59 lines (49 loc) · 1.81 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const button = document.querySelector(".button-no-pushable");
const whyNo = [
"ILL CRY IF YOU CHOOSE NO",
"WHY NOT BABY?",
"PUHLEASE MY LOVE?",
"PUHLEASSSEEEE BABYY",
"NAH YOU WON'T EVER CLICK THIS NO BUTTON",
"DON'T EVEN TRY",
"BABY PUHLEAAAAAAAAAASEEEE",
"NAH I AIN'T GIVING UP",
"I STILL LOVE YOU VERY MUCH MUCH MUCH",
"PWEASESEEEE",
"JUST THIS TIME PWEASE",
"COME ON GORGEOUS PLEASE",
"YOU'RE STILL THE PRETTIEST WOMAN IN MY EYES",
];
if (button) {
["mouseover", "click"].forEach(function (type) {
button.addEventListener(type, function () {
const maxTop = window.innerHeight - button.offsetHeight - 10; // Prevents overflow
const maxLeft = window.innerWidth - button.offsetWidth - 10;
const top = getRandomNum(maxTop);
const left = getRandomNum(maxLeft);
console.log("New position -> Top:", top, "Left:", left);
moveElement(button, "left", left);
moveElement(button, "top", top);
// Change only the text inside `.button-82-front`
const frontText = button.querySelector(".button-82-front");
if (frontText) frontText.textContent = getRandomQuote();
});
});
} else {
console.error("Button not found!");
}
const moveElement = (element, animeType, pixels) => {
anime({
targets: element,
[animeType]: `${pixels}px`,
easing: 'easeOutElastic(1, 0.7)',
duration: 800,
});
};
const getRandomNum = (max, offset = 0) => {
return Math.max(offset, Math.min(Math.floor(Math.random() * max), max - offset)); // Keeps within screen bounds
};
const getRandomQuote = () => {
const index = getRandomNum(whyNo.length);
return whyNo[index];
};