Skip to content
Open
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
30 changes: 15 additions & 15 deletions static/scripts/hero-glass.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ const updateScene = () => {
root.style.setProperty("--cursor-x", `${pointer.x}px`);
root.style.setProperty("--cursor-y", `${pointer.y}px`);

if (hero && heroInView) {
if (heroRectDirty || !heroRect) {
refreshHeroRect();
}
const relX = (pointer.x - heroRect.left) / heroRect.width - 0.5;
const relY = (pointer.y - heroRect.top) / heroRect.height - 0.5;
const clampedX = Math.max(-0.5, Math.min(0.5, relX));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing clampedX and clampedY, which can allow excessive tilt when the pointer is far from the hero area. The optimization should skip updates when the hero is offscreen, but the tilt values should still stay clamped. please revert 37 and 38 line

const clampedY = Math.max(-0.5, Math.min(0.5, relY));
hero.style.setProperty("--tilt-x", `${(-clampedY * 7).toFixed(2)}deg`);
hero.style.setProperty("--tilt-y", `${(clampedX * 9).toFixed(2)}deg`);
if (!hero || !heroInView) {
frame = null;
return;
}

if (heroRectDirty || !heroRect) {
refreshHeroRect();
}
const relX = (pointer.x - heroRect.left) / heroRect.width - 0.5;
const relY = (pointer.y - heroRect.top) / heroRect.height - 0.5;
hero.style.setProperty("--tilt-x", `${(-relY * 7).toFixed(2)}deg`);
hero.style.setProperty("--tilt-y", `${(relX * 9).toFixed(2)}deg`);


tiltTargets.forEach((target) => {
const rect = target.getBoundingClientRect();
Comment thread
Katotodan marked this conversation as resolved.
Expand All @@ -54,7 +56,7 @@ const updateScene = () => {
const handlePointer = (event) => {
pointer.x = event.clientX;
pointer.y = event.clientY;
scheduleUpdateScene();
heroInView && scheduleUpdateScene();
};

window.addEventListener("pointermove", handlePointer, { passive: true });
Expand All @@ -74,7 +76,7 @@ window.addEventListener("scroll", () => {
heroRectDirty = true;
}, { passive: true });

if (hero) {
if(hero){
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
Expand All @@ -85,17 +87,15 @@ if (hero) {
heroRect = null;
} else {
heroRectDirty = true;
scheduleUpdateScene();
}
scheduleUpdateScene();
});
},
{ threshold: 0.2 },
);
observer.observe(hero);
}

floaters.forEach((item, index) => {
item.style.animationDelay = `${index * -2.5}s`;
});

updateScene();
Loading