You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Placeholder Component for React using an Intersection Observer. Especially designed for next-optimized-images new canary version.
Usage Examples:
Normal LQIP Placeholder for an Image
importImgfrom'react-optimized-image';importTestImgfrom'test.png';importTestImgLqipfrom'test.png?lqip';
...
<IntersectionPlaceholdersrc={TestImg}// original image needed for having the right dimensionslqip={TestImgLqip}// pass your placeholder image hereobserverOptions={{threshold: 0.5}}// you can also pass options for the intersection observer. Use the same config object as you would use to init the intersection observer.><Imgsrc={TestImg}/></IntersectionPlaceholder>
Works also with video tags (uses onLoadedData instead of onLoad)
importTestImgfrom'test.png';importTestImgLqipfrom'test.png?lqip';
...
<IntersectionPlaceholdersrc={TestImg}lqip={TestImgLqip}observerOptions={{threshold: 0.5}}><videopreload="auto"width="100%"autoPlayplaysInlineloopmuted><sourcesrc="/static/test.mp4"type="video/mp4"/><sourcesrc="/static/test.webm"type="video/webm"/>
Your browser does not support the video tag.
</video></IntersectionPlaceholder>
Can also get nested to support multiple Placeholders like: LQIP => normal Image => Video
importTestImgfrom'test.png';importTestImgLqipfrom'test.png?lqip';
...
<IntersectionPlaceholdersrc={TestImg}lqip={TestImgLqip}><IntersectionPlaceholdersrc={TestImg}lqip={TestImg}stdDeviation={0}><videopreload="auto"width="100%"autoPlayplaysInlineloopmuted><sourcesrc="/static/test.mp4"type="video/mp4"/><sourcesrc="/static/test.webm"type="video/webm"/>
Your browser does not support the video tag.
</video></IntersectionPlaceholder></IntersectionPlaceholder>
Options (props):
src: original image. Needed for right dimensions
lqip: the placeholder image.
children: any react component which has an onLoad or onLoadedData event
observerOptions (optional): options for the intersection observer
stdDeviation (optional, default 18px): the amount of blured pixels for the placeholders
className (optional): set the className of the wrapper div to style this component
placeholderClassName (optional): set the className of the svg placeholder to style your placeholder