Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed animated cursor #380

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
width: 24px;
border-radius: 24px;
background-color: black;
position: fixed;
position: relative;
top: 0;
left: 0;

pointer-events: none;
z-index: 99999999;

Expand Down Expand Up @@ -538,6 +539,40 @@ <h3>Saarthi</h3>
src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

<!-- JavaScript for toggling modal -->
<script>
const circle = document.querySelector('.circle');

// Hide the cursor after a timeout or when it leaves the screen
let hideTimeout;

// Update cursor position
document.addEventListener('mousemove', (e) => {
circle.style.top = `${e.clientY - circle.offsetHeight / 2}px`;
circle.style.left = `${e.clientX - circle.offsetWidth / 2}px`;

// Show the cursor when it's moving
circle.style.opacity = 1;

// Clear any previous hide timeout
clearTimeout(hideTimeout);

// Set a timeout to hide the cursor after inactivity
hideTimeout = setTimeout(() => {
circle.style.opacity = 0;
}, 1000); // 1 second delay before hiding
});

// Hide cursor when scrolling
document.addEventListener('scroll', () => {
circle.style.opacity = 0;
});

// Re-show cursor when mouse moves after scrolling
document.addEventListener('mousemove', () => {
circle.style.opacity = 1;
});
</script>

<script>
document.addEventListener("DOMContentLoaded", function () {
const languageIcon = document.getElementById('languageIcon');
Expand Down Expand Up @@ -617,8 +652,8 @@ <h3>Saarthi</h3>
circle.y = lerp(circle.y, y, 0.4);

// Positioning the circle closer to the cursor
circle.style.left = circle.x - circle.offsetWidth / 2 + "px";
circle.style.top = circle.y - circle.offsetHeight / 2 + "px";
circle.style.left = circle.x - circle.offsetWidth / 4 + "px";
circle.style.top = circle.y - circle.offsetHeight / 4 + "px";

// Scale down each circle progressively to create depth
circle.style.transform = `scale(${(circles.length - index) / circles.length})`;
Expand Down
Loading