An open API service indexing awesome lists of open source software.

https://github.com/jean-tinland/lazy-icon-web-component

A web component lazy loading icons from individual sprites
https://github.com/jean-tinland/lazy-icon-web-component

lazy-icon lazy-loading web-components

Last synced: 10 months ago
JSON representation

A web component lazy loading icons from individual sprites

Awesome Lists containing this project

README

          

# lazy-icon-web-component

A web component lazy loading icons from individual sprites.

It uses the `IntersectionObserver` API to load the icon only when it is in the viewport. If the browser doesn't support this API, icon is loaded immediately.

## Setup

You'll need to expose your icons in a distant or local folder.

![Setup](./setup.png)

Each icon must be a well named file containing a `` sprite with a `` identified by the id `icon`.

```html



```

## Configuration & loading

Copy this `lazy-icon.js` script inside your project.

Create the configuration object then insert bellow a ` anywhere in your HTML:

```html
<!doctype html>
<html>
<head>
<!-- head content -->
</head>
<body>
<!-- body content -->

<script>
window.lazyIconConfig = {
// spriteUrl can be a relative or absolute url
spriteUrl: "/public/images/icons"
};