-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHTML Mascot.txt
31 lines (24 loc) · 1.02 KB
/
HTML Mascot.txt
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
<img id="animated-mascot" src="https://s3.gifyu.com/images/Oanl.gif" style="position: fixed; bottom: 0; right: 0; cursor: move; z-index: 9999;">
<script>
const mascot = document.getElementById("animated-mascot");
mascot.addEventListener("mousedown", startDragging);
function startDragging(event) {
let shiftX = event.clientX - mascot.getBoundingClientRect().left;
let shiftY = event.clientY - mascot.getBoundingClientRect().top;
moveAt(event.pageX, event.pageY);
function moveAt(pageX, pageY) {
mascot.style.left = pageX - shiftX + "px";
mascot.style.top = pageY - shiftY + "px";
}
function onMouseMove(event) {
moveAt(event.pageX, event.pageY);
}
function stopDragging() {
document.removeEventListener("mousemove", onMouseMove);
mascot.removeEventListener("mouseup", stopDragging);
}
document.addEventListener("mousemove", onMouseMove);
mascot.addEventListener("mouseup", stopDragging);
event.preventDefault();
}
</script>