Skip to content

Commit ab9333d

Browse files
authored
Unicorn scroll edits improvement (#3084)
* Unicorn scroll edits improvement * fixes double-scrolling
1 parent 6962f87 commit ab9333d

3 files changed

Lines changed: 40 additions & 6 deletions

File tree

apps/web/client/src/app/_components/hero/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export function Hero() {
3030
return (
3131
<div className="relative flex h-full w-full flex-col items-center text-center text-lg">
3232
<UnicornBackground />
33-
<div className="mb-42 flex h-full w-full flex-col items-center justify-center gap-10 pt-12">
33+
{/* pointer-events-none allows mouse events to pass through to the canvas behind */}
34+
<div className="pointer-events-none mb-42 flex h-full w-full flex-col items-center justify-center gap-10 pt-12">
3435
<div className="relative z-20 flex flex-col items-center gap-3 pt-8 pb-2">
3536
{!isShortScreen && (
3637
<motion.div
@@ -43,7 +44,7 @@ export function Hero() {
4344
href="https://www.ycombinator.com/companies/onlook/jobs/e4gHv1n-founding-engineer-fullstack"
4445
target="_blank"
4546
rel="noopener noreferrer"
46-
className="hover:bg-foreground-secondary/20 border-foreground-secondary/20 text-foreground-secondary inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-xs backdrop-blur-sm transition-all duration-200 hover:scale-102"
47+
className="pointer-events-auto hover:bg-foreground-secondary/20 border-foreground-secondary/20 text-foreground-secondary inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-xs backdrop-blur-sm transition-all duration-200 hover:scale-102"
4748
>
4849
We're hiring engineers
4950
<Icons.ArrowRight className="h-4 w-4" />
@@ -81,7 +82,7 @@ export function Hero() {
8182
<HighDemand />
8283
<CreateError />
8384
</div>
84-
<div className="relative z-20 hidden flex-row items-center gap-4 sm:flex">
85+
<div className="pointer-events-auto relative z-20 hidden flex-row items-center gap-4 sm:flex">
8586
<motion.div
8687
initial={{ opacity: 0, y: 10 }}
8788
animate={{ opacity: 1, y: 0 }}
@@ -102,7 +103,9 @@ export function Hero() {
102103
</Button>
103104
</motion.div>
104105
</div>
105-
<MobileEmailCapture />
106+
<div className="pointer-events-auto w-full flex justify-center">
107+
<MobileEmailCapture />
108+
</div>
106109
</div>
107110
</div>
108111
);

apps/web/client/src/app/_components/hero/unicorn-background.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
'use client';
22

33
import { motion } from 'motion/react';
4+
import { useEffect, useRef } from 'react';
45
import UnicornScene from 'unicornstudio-react/next';
56

67
export function UnicornBackground() {
8+
const containerRef = useRef<HTMLDivElement>(null);
9+
10+
useEffect(() => {
11+
const container = containerRef.current;
12+
if (!container) return;
13+
14+
// Handle wheel events to allow scrolling while keeping mouse interactivity
15+
const handleWheel = (e: WheelEvent) => {
16+
// Prevent the default to avoid double-scrolling
17+
e.preventDefault();
18+
// Manually trigger scroll on the window
19+
window.scrollBy({
20+
top: e.deltaY,
21+
left: e.deltaX,
22+
behavior: 'auto',
23+
});
24+
};
25+
26+
// Use passive: false so we can call preventDefault()
27+
container.addEventListener('wheel', handleWheel, { passive: false });
28+
29+
return () => {
30+
container.removeEventListener('wheel', handleWheel);
31+
};
32+
}, []);
33+
734
return (
835
<motion.div
36+
ref={containerRef}
937
className="absolute inset-0 z-0 h-screen w-screen"
1038
style={{
11-
pointerEvents: 'none',
1239
willChange: 'opacity',
1340
transform: 'translateZ(0)',
1441
}}

apps/web/client/src/styles/globals.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
html,
1+
html {
2+
overscroll-behavior: none;
3+
}
4+
25
body {
36
overscroll-behavior: none;
47
overflow-x: hidden;
8+
overflow-y: auto;
59
}
610

711
@view-transition {

0 commit comments

Comments
 (0)