Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/phucbm/bg-prlx

No-dependency npm package to create parallax effect for images.
https://github.com/phucbm/bg-prlx

npm-package parallax

Last synced: 25 days ago
JSON representation

No-dependency npm package to create parallax effect for images.

Awesome Lists containing this project

README

        

# bg-prlx

[![release](https://badgen.net/github/release/phucbm/bg-prlx/?cache=600)](https://github.com/phucbm/bg-prlx/releases/latest)
[![license](https://badgen.net/github/license/phucbm/bg-prlx/)](https://github.com/phucbm/bg-prlx/blob/main/LICENSE)

> Create parallax effect for inline `background-image` or `object-fit:cover`.

## Install

```sh
npm i bg-prlx
```

## Usage

Simply add attribute `data-parallax` to your HTML.

### Setup HTML

With inline `background-image`:

```html




```

Or with ``:

```html


Photo

```

> Note: In order to have parallax effect, the block that contains the image must have a smaller height
> than the real image's height. In the example above, the image size is 1920x1280, while the block size has ratio of 1920x800.

### Run script

```js
import backgroundParallax from "./index.js";

backgroundParallax();
```

## API

### backgroundParallax(elements?)

#### elements

Type: `DOM element`

Default value is `document.querySelectorAll("[data-parallax]:not(.parallax-enabled)")`.

## License

[MIT License](https://github.com/phucbm/bg-prlx/blob/main/LICENSE)

Copyright (c) 2022 Minh-Phuc Bui