# lazim

> Super tiny and simple image lazy load library.

Latest version **2.0.1** (published 2019-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install lazim
pnpm add lazim
yarn add lazim
bun add lazim
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2019-06-07 |
| First published | 2019-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | estrattonbailey |
| Maintainers | estrattonbailey |

## Links

- npm: https://www.npmjs.com/package/lazim
- Repository: https://github.com/estrattonbailey/lazim
- Homepage: https://github.com/estrattonbailey/lazim#readme
- Issues: https://github.com/estrattonbailey/lazim/issues
- npm.io page: https://npm.io/package/lazim

## Dependencies (1)

- [vsbl](https://npm.io/package/vsbl.md) ^1.3.3

## Recent versions

- 2.0.1 (latest) — 2019-06-07
- 2.0.0 — 2019-06-07
- 1.0.0 — 2019-03-15

## README

# lazim
Small, simple image lazy loader. **800 bytes gzipped.**

## Install
```bash
npm i lazim --save
```

## Usage
`lazim` doesn't really care about your markup. This works:
```html
<img data-src='/image.jpg' />
```
But so does this:
```html
<div data-src='/image.jpg'>
  <img />
</div>
```
And so does this:
```html
<div data-src='/image.jpg'>
  <div
    <img />
  </div>
  <h2>silly image</h2>
</div>
```

### Instantiating
To run lazim, import `bind` and call it:
```javascript
import { bind } from 'lazim'

bind()
```

You can also pass a different attribute, if you don't like `data-src`:
```javascript
bind('data-url')
```

`lazim` checks if there are images in the viewport on initial load, but in the
event you need to run this again when adding/animating elements:
```javascript
import { update } from 'lazim'

update()
```

Once bound, `lazim` removes the `data-src` attribute to prevent duplicate event
listeners.

### Animation
`lazim` adds a couple helper classes to the element you defined `data-src` on:

When visible in the viewport, it will receive an `is-visible` class. When the
image loads, it receives an `is-loaded` class.
```html
<div class='is-visible is-loaded'>
  <img src='/image.jpg' />
</div>
```

### Re-binding
If you're using a PJAX library like
[operator](https://github.com/estrattonbailey/operator), you'll need to re-bind
new images that are added to the DOM on each page load. In that case, just call
`bind` again whenever the page updates:
```javascript
router.on('after', () => bind())
```

## License
MIT License © [Eric Bailey](https://estrattonbailey.com)

---
_Source: https://npm.io/package/lazim · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
