Image
Requires:
@ray-js/ray≥0.5.10
Description
Image component supporting multiple cropping and scaling modes.
Props
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
src | string | No | - | Image source URL |
mode | "scaleToFill" | "aspectFit" | "aspectFill" | "widthFix" | "heightFix" | "top" | "bottom" | "center" | "left" | "right" | "top left" | "top right" | "bottom left" | "bottom right" | No | scaleToFill | Image cropping and scaling modes |
lazyLoad | boolean | No | false | Lazy load; loads after entering a certain viewport range |
fadeDuration | number | No | 0 | Fade-in duration during loading, in ms |
| No | - | Triggered when loading fails | ||
| No | - | Triggered when loading completes |
Valid Values
mode
| Value | Description | Since |
|---|---|---|
scaleToFill | Scaling mode: scales the image without preserving the aspect ratio, stretching its width and height to completely fill the image element | - |
aspectFit | Scale mode: preserve aspect ratio and ensure the long edge is fully visible | - |
aspectFill | Scale mode: preserve aspect ratio and ensure only the short edge is fully visible | - |
widthFix | Scale mode: fixed width, auto height; preserve the original aspect ratio | - |
heightFix | Scale mode: fixed height, auto width; preserve the original aspect ratio | - |
top | Crop mode: do not scale; display only the top region of the image | - |
bottom | Crop mode: do not scale; display only the bottom region of the image | - |
center | Crop mode: do not scale; display only the center region of the image | - |
left | Crop mode: do not scale; display only the left region of the image | - |
right | Crop mode: do not scale; display only the right region of the image | - |
top left | Crop mode: do not scale; display only the top-left region of the image | - |
top right | Crop mode: do not scale; display only the top-right region of the image | - |
bottom left | Crop mode: do not scale; display only the bottom-left region of the image | - |
bottom right | Crop mode: do not scale; display only the bottom-right region of the image | - |
Examples
Basic usage
Scaling modes
Lazy load and fade-in
Notes
- Some low-end devices have poor WebP compatibility, which may cause images to fail to display or render incorrectly. Prefer image formats with more stable compatibility; if WebP must be used, verify rendering on target devices and provide a fallback image.