-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·27 lines (23 loc) · 1.35 KB
/
index.js
File metadata and controls
executable file
·27 lines (23 loc) · 1.35 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
'use strict';
const image = document.querySelector('.dragon-img');
// Function to check if the mouse is over the leftmost 100 pixels of the image
function isMouseOverDragonHead(event) {
const rect = image.getBoundingClientRect(); // Get the position and size of the image
const mouseX = event.clientX; // Get the X position of the mouse
// Check if the mouse is in the leftmost 100 pixels
return mouseX >= rect.left && mouseX <= rect.left + 200;
}
// Change the image on mouse move (while the mouse is over the image)
image.addEventListener('mousemove', function(event) {
if (isMouseOverDragonHead(event)) {
image.src = 'https://shadowthehedgehog.ca/assets/dragon_header_eating.png'; // Change to the hover image
image.style.cursor = 'url(https://shadowthehedgehog.ca/assets/scared_cursor.png), auto';
} else {
image.src = 'https://shadowthehedgehog.ca/assets/dragon_header.png'; // Reset to the original image when the mouse moves away
image.style.cursor = 'url(https://shadowthehedgehog.ca/assets/neutral_cursor.png), auto';
}
});
image.addEventListener('mouseleave', function() {
image.src = 'https://shadowthehedgehog.ca/assets/dragon_header.png'; // Revert to the original image when the mouse leaves the image
image.style.cursor = 'url(https://shadowthehedgehog.ca/assets/neutral_cursor.png), auto';
});