Skip to content

Image

Image container with lazy loading, custom placeholder, load failure, and image preview support, while retaining original img characteristics.

Basic Usage

The fit attribute determines how the image adapts to the container, same as native object-fit.

fill
Loading...
contain
Loading...
cover
Loading...
none
Loading...
scale-down
Loading...
Basic Usage

Placeholder and Load Failure

Customize placeholder content via placeholder and error slots.

Default Error
Loading...
Custom Error
Loading...
Placeholder and Load Failure

Lazy Load

TIP

Browser-native loading attribute. You can try replacing lazy="true" with loading="lazy".

If the current browser supports native image lazy loading, native capabilities are prioritized; otherwise, scroll listening will be used to achieve the same effect.

Enable lazy loading via lazy, so images load only when scrolled into view. You can set the scroll container via scroll-container; if undefined, it defaults to the nearest parent element with overflow set to auto or scroll.

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Lazy Load

Image Preview

Enable preview functionality via preview-src-list.

Loading...
Image Preview

Manual Preview Call

Manually invoke the preview via the yh-image-viewer component. This is useful when you don't want to show thumbnails but want to trigger a preview on clicking an element (like a button or link). Manual calls for viewerjs mode are also supported.

Manual Preview Call

Viewer.js Preview (Extension)

When the built-in previewer isn't enough, switch to the more powerful viewerjs mode. It supports advanced features like slideshows, fullscreen, flipping, and thumbnail navigation.

Loading...
Viewer.js Advanced Preview

Use in Nuxt

The Image component fully supports Nuxt 3 SSR mode. We have fully considered server-client compatibility in its implementation of lazy loading and previewing.

Nuxt SSR Loading...

Supports auto-import and SSR placeholder rendering

Use in Nuxt

SSR Notes:

  • ✅ Supports server-side placeholder rendering (Placeholder Slot).
  • ✅ Lazy loading starts listening automatically after client-side activation.
  • ✅ Previewer component uses Teleport to mount to body on the client.
  • ✅ Perfectly compatible with Nuxt auto-import mechanism.

API

Props

PropDescriptionTypeDefault
srcImage source addressstring
fitHow image fits container, same as native object-fit'fill' | 'contain' | 'cover' | 'none' | 'scale-down'
lazyWhether to enable lazy loadingbooleanfalse
preview-src-listPreview liststring[][]
z-indexPreview z-indexnumber2000
initial-indexStart index of previewnumber0
close-on-press-escapeClose preview via ESCbooleantrue
hide-on-click-modalClose preview via clicking maskbooleanfalse
infiniteWhether to loop previewbooleantrue
zoom-ratePreview zoom ratenumber1.2
show-progressShow toolbar in preview modebooleantrue
preview-teleportedTeleport preview container to bodybooleantrue
scroll-containerScroll container for lazy loadingstring | HTMLElement
viewer-modePreview mode: 'default' (built-in), 'viewerjs' (external)'default' | 'viewerjs''default'
viewer-optionsOptions passed to viewerjsobject{}
altNative alt attributestring
crossoriginNative crossorigin attributestring

Events

Event NameDescriptionCallback Parameters
loadTriggered on image load success(event: Event) => void
errorTriggered on image load failure(event: Event) => void
switchTriggered on preview image switch(index: number) => void
showTriggered when preview is shown
closeTriggered when preview is closed

Slots

Slot NameDescription
placeholderPlaceholder when image is not loaded
errorContent for load failure

ImageViewer API

If you need to use the previewer independently, use yh-image-viewer.

ImageViewer Props

PropDescriptionTypeDefault
url-listPreview image source liststring[][]
z-indexPreview z-indexnumber2000
indexStart index of previewnumber0
infiniteWhether to loop previewbooleantrue
hide-on-click-modalClose preview via clicking maskbooleanfalse
close-on-press-escapeClose preview via ESCbooleantrue
zoom-ratePreview zoom ratenumber1.2
show-progressWhether to show toolbarbooleantrue
teleportedWhether to teleport to bodybooleantrue
viewer-modePreview mode'default' | 'viewerjs''default'
viewer-optionsViewer.js optionsobject{}

ImageViewer Events

Event NameDescriptionCallback Parameters
switchTriggered on image switch(index: number) => void
closeTriggered when preview closed

Theme Variables

Customizes local styles via CSS variables. All colors are interfaced with the global theme and support dark mode:

VariableDescriptionDefault
--yh-image-placeholder-bg-colorPlaceholder background colorvar(--yh-fill-color-light)
--yh-image-placeholder-text-colorPlaceholder text colorvar(--yh-text-color-placeholder)
--yh-image-error-bg-colorError area background colorvar(--yh-fill-color-extra-light)
--yh-image-error-text-colorError area text colorvar(--yh-text-color-placeholder)
--yh-image-border-radiusImage border radiusvar(--yh-radius-md)
--yh-image-viewer-mask-bg-colorPreview mask background colorvar(--yh-mask-color)
--yh-image-viewer-btn-bg-colorPreview controller button backgroundvar(--yh-text-color-regular)
--yh-image-viewer-btn-colorPreview controller button icon colorvar(--yh-color-white)
--yh-image-viewer-btn-hover-bg-colorPreview controller button hovervar(--yh-color-primary)

Released under the MIT License.