Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/tsung-ju/parallax-background-image

simple, responsive parallax scrolling effect.
https://github.com/tsung-ju/parallax-background-image

parallax

Last synced: 11 days ago
JSON representation

simple, responsive parallax scrolling effect.

Awesome Lists containing this project

README

        

# parallax-background-image

simple, responsive parallax scrolling effect.

## Features

- works on mobile devices
- automatically switch to [pure CSS parallax effect](https://keithclark.co.uk/articles/pure-css-parallax-websites/) if supported by the browser
- zero dependencies
- simple WebComponents-based api

## Demo

## Installation

```sh
npm install parallax-background-image
```

```js
import "parallax-background-image";
```

Or use a CDN:

```html

```

## Basic usage

```html


#wrapper {
position: fixed;
height: 100%;
width: 100%;
}



... contents



nesting is also supported


```

For complete example see `demo.html`

## API

### ``

A scrollable container block. Used to measure the scrolling position of each `` and (when backend=3d) set parameters for perspective transform. Each `` must be contained (directly or indirectly) in an `` for this library to work.

#### Attributes

- `backend`: Selects the method used to apply the parallax effect.
- Supported values: `2d`, `3d`
- Defaults to `3d` if the browser is Blink-based, `2d` otherwise.

### ``

Element with parallax scrolling effect.

#### Attributes

- `image-src`: URL to the background image.
- Required.
- `velocity-x` `velocity-y`: Controls how fast the background scrolls.
- `velocity=1` means scrolling at the same speed as the parent (no parallaxing).
- `velocity=0` means the background does not move at all (fixed background).
- Accepts floating point numbers.
- `velocity-x` defaults to `1`, `velocity-y` defaults to `0.8`.
- `align-x` `align-y`: Aligns the background to the container.
- Accepts `center`, `left`, `right`, `top`, `bottom` and percentage strings (e.g. `80%`).
- `align-x`, `align-y` both defaults to `center`.