st-img
v0.3.0
Published
Web Component built with Stencil to lazy load images
Downloads
4,531
Readme
st-img
What is it?
st-img is a web component built with Stencil that allows you to lazy load images as the user scrolls them into the viewport. On supported browsers (Chrome and chrome based browsers, Firefox and Edge) it uses IntersectionObserver to accomplish this functionality. For Safari and IE it simply falls back to setTimeout.
Usage
To use this component in your app, no matter what framework you are using, follow these steps:
- pop this script tag
<script async defer src='https://unpkg.com/[email protected]/dist/stimg.js'></script>
into your index.html
API
Properties:
- src (string): the path or url to the image you want to load
- alt (string): the value you want to use for the alt property of the image https://www.w3schools.com/tags/att_img_alt.asp
Examples
<st-img src="https://madeby.google.com/static/images/google_g_logo.svg" alt="google"></st-img>