Directory
- Welcome
LazyImage Component
The LazyImage component provides an enhanced image loading experience with support for skeleton loading states, thumbnail previews, and intelligent preloading. Perfect for optimizing image loading performance while maintaining a smooth user experience.
Key Features
-
Smart Preloading: Customizable preload distance for optimized loading
-
Loading States: Built-in skeleton and thumbnail loading options
-
Flexible Integration: Works with both local and remote images
Basic Usage
Create a simple lazy-loaded image:
---import { LazyImage } from '@/components/NST-components/UI';import myImage from '@/assets/images/example.jpg';---
<LazyImage imageProps={{ src: myImage, alt: 'Example image', width: 800, height: 600, }}/>
Loading Variants
Skeleton Loading
Show a skeleton loading state while the image loads:
<LazyImage variant="skeleton" imageProps={{ src: myImage, alt: "Example with skeleton", width: 800, height: 600 }}/>
Thumbnail Preview
Display a low-resolution thumbnail while loading the main image:
<LazyImage variant="thumbnail" imageProps={{ src: highResImage, alt: "High resolution image", width: 1200, height: 800 }} thumbnailProps={{ src: lowResImage, alt: "Low resolution preview", width: 120, height: 80 }}/>
Smart Preloading
Configure preloading distance to start loading images before they enter the viewport:
<LazyImage preloadDistance={200} // Start loading 200px before image enters viewport imageProps={{ src: myImage, alt: "Preloaded image", width: 800, height: 600 }}/>
Component API
Prop | Type | Default | Description |
---|---|---|---|
imageProps | ComponentProps<typeof Image> | - | Props for the main image |
variant | skeleton | thumbnail | Loading state variant | |
skeletonProps | ComponentProps<typeof Skeleton> | Props for skeleton loader | |
thumbnailProps | ComponentProps<typeof Image> | Props for thumbnail image | |
preloadDistance | number | Distance in pixels to start preloading |
Limited Time Launch Sale
Optimize your image loading experience with our LazyImage component. Get started with our AstroJS starter template today!
GET 60% OFF!