Skip to content

Commit

Permalink
mouse smoothing update
Browse files Browse the repository at this point in the history
Key changes made:

Increased the base smoothing factor from 0.1 to 0.25 for faster response
Added a separate smoothing factor (0.35) for hover states
Added an isHovering state to track when over interactive elements

You can adjust these values to find the perfect balance:

Higher values (closer to 1.0) = more immediate response
Lower values (closer to 0) = more smoothing/laziness

Try these values and let me know if you'd like it even faster or slower:

For even faster response: Use 0.35 and 0.45
For slightly slower: Use 0.2 and 0.3
  • Loading branch information
macedonianluke committed Oct 25, 2024
1 parent 1b47ca6 commit c279d9c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions js/v2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ document.addEventListener('DOMContentLoaded', () => {
if (menuButton && menu) {
menuButton.addEventListener('click', () => {
menu.classList.toggle('active');
// Optional: Toggle button text
menuButton.textContent = menu.classList.contains('active') ? 'Close' : 'Menu';
});

// Close menu when clicking menu links
const menuLinks = document.querySelectorAll('.menu-nav a');
menuLinks.forEach(link => {
link.addEventListener('click', () => {
Expand All @@ -19,7 +17,6 @@ document.addEventListener('DOMContentLoaded', () => {
});
});

// Add escape key functionality to close menu
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && menu.classList.contains('active')) {
menu.classList.remove('active');
Expand All @@ -40,13 +37,17 @@ document.addEventListener('DOMContentLoaded', () => {
let mouseY = 0;
let cursorX = 0;
let cursorY = 0;
let isHovering = false;

function updateCursor() {
// Use different smoothing factors based on whether hovering over interactive elements
const smoothing = isHovering ? 0.35 : 0.25; // Increased from 0.1 to 0.25/0.35

const dx = mouseX - cursorX;
const dy = mouseY - cursorY;

cursorX += dx * 0.1;
cursorY += dy * 0.1;
cursorX += dx * smoothing;
cursorY += dy * smoothing;

cursor.style.left = `${cursorX}px`;
cursor.style.top = `${cursorY}px`;
Expand All @@ -66,10 +67,12 @@ document.addEventListener('DOMContentLoaded', () => {
interactiveElements.forEach(el => {
el.addEventListener('mouseenter', () => {
cursor.classList.add('hover');
isHovering = true;
});

el.addEventListener('mouseleave', () => {
cursor.classList.remove('hover');
isHovering = false;
});
});

Expand Down

0 comments on commit c279d9c

Please sign in to comment.