Cursor Attractor And Gravity Image Demo
fancy/cursor-attractor-and-gravity-image-demoFreeBlock
A block component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/cursor-attractor-and-gravity-image-demo.jsonSource
1import useScreenSize from "@/hooks/use-screen-size"2import Gravity, {3 MatterBody,4} from "@/components/fancy/physics/cursor-attractor-and-gravity"56export default function Preview() {7 const screenSize = useScreenSize()89 const getImageCount = () => {10 if (screenSize.lessThan("sm")) return 5011 if (screenSize.lessThan("md")) return 6012 if (screenSize.lessThan("lg")) return 7013 return 8014 }1516 const getMaxSize = () => {17 if (screenSize.lessThan("sm")) return 4018 if (screenSize.lessThan("md")) return 5019 return 6020 }2122 const getMinSize = () => {23 if (screenSize.lessThan("sm")) return 1024 if (screenSize.lessThan("md")) return 2025 return 2026 }2728 return (29 <div className="w-dvw h-dvh flex flex-col relative justify-center items-center md:items-end bg-white">30 <div>31 <p className="z-20 text-2xl sm:text-3xl md:text-3xl text-foreground dark:text-muted md:pr-24">32 join the <span className="font-calendas italic">community</span>33 </p>34 </div>35 <Gravity36 attractorPoint={{ x: "33%", y: "50%" }}37 attractorStrength={0.0005}38 cursorStrength={-0.004}39 cursorFieldRadius={screenSize.lessThan("sm") ? 100 : 200}40 className="w-full h-full"41 >42 {[...Array(getImageCount())].map((_, i) => {43 const size = Math.max(getMinSize(), Math.random() * getMaxSize())44 return (45 <MatterBody46 key={i}47 matterBodyOptions={{ friction: 0.5, restitution: 0.2 }}48 x={`${Math.random() * 100}%`}49 y={`${Math.random() * 30}%`}50 >51 <img52 src={`https://randomuser.me/api/portraits/${i % 2 === 0 ? "men" : "women"}/${i}.jpg`}53 alt={`Avatar ${i}`}54 className="rounded-full object-cover hover:cursor-pointer"55 style={{56 width: `${size}px`,57 height: `${size}px`,58 }}59 />60 </MatterBody>61 )62 })}63 </Gravity>64 </div>65 )66}
What it pulls in
Other registry items
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient Demoanimated-gradient-demo | fancy | Blocks | Free | no deps | |
| Basic Number Ticker Demobasic-number-ticker-demo | fancy | Blocks | Free | no deps | |
| Box Carousel Autoplay Demobox-carousel-autoplay-demo | fancy | Blocks | Free | 1 dep | |
| Box Carousel Demobox-carousel-demo | fancy | Blocks | Free | 1 dep | |
| Box Carousel Video Demobox-carousel-video-demo | fancy | Blocks | Free | 1 dep | |
| Breathing Text Demobreathing-text-demo | fancy | Blocks | Free | no deps | |
| Circling Elements Democircling-elements-demo | fancy | Blocks | Free | no deps | |
| Circling Elements Easing Democircling-elements-easing-demo | fancy | Blocks | Free | no deps |
