-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractive Star Cursor
77 lines (69 loc) · 2.44 KB
/
Interactive Star Cursor
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Button with Custom Cursor</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
margin: 0;
font-family: Arial, sans-serif;
}
.modern-button {
padding: 15px 30px;
font-size: 16px;
color: #ffffff;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.modern-button:hover {
background-color: #0056b3;
transform: translateY(-2px);
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.2);
}
/* Custom cursor */
.modern-button:hover {
cursor:none /* Hide default cursor */
}
/* Using a pseudo-element to create the star cursor */
.star-cursor {
position: absolute;
pointer-events: none; /* Prevent the cursor from interfering with the button */
font-size: 24px; /* Adjust size of the star */
color: #ffcc00; /* Color of the star */
transition: transform 0.1s ease; /* Smooth movement */
display: none; /* Initially hidden */
}
</style>
</head>
<body>
<button class="modern-button">Click Me</button>
<div class="star-cursor">*</div>
<script>
const button = document.querySelector('.modern-button');
const starCursor = document.querySelector('.star-cursor');
// Show the star cursor on button hover
button.addEventListener('mouseenter', () => {
starCursor.style.display = 'block';
});
button.addEventListener('mouseleave', () => {
starCursor.style.display = 'none';
});
// Update the position of the star cursor
document.addEventListener('mousemove', (e) => {
starCursor.style.left = e.pageX + 'px';
starCursor.style.top = e.pageY + 'px';
starCursor.style.transform = 'translate(-50%, -50%)'; // Center the star cursor
});
</script>
</body>
</html>