# magic-scrolls

> An es6 class to tween element styles based on the scroll position

Latest version **0.1.8** (published 2022-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install magic-scrolls
pnpm add magic-scrolls
yarn add magic-scrolls
bun add magic-scrolls
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.8 |
| Published | 2022-05-26 |
| First published | 2021-04-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Emmanuel Davies |
| Maintainers | meteora-digital |
| Keywords | JavaScript, es6, class, scroll, tweening, animation |

## Links

- npm: https://www.npmjs.com/package/magic-scrolls
- Repository: https://github.com/meteora-digital/magic-scrolls
- Homepage: https://github.com/meteora-digital/magic-scrolls#readme
- Issues: https://github.com/meteora-digital/magic-scrolls/issues
- npm.io page: https://npm.io/package/magic-scrolls

## Dependencies (1)

- [meteora](https://npm.io/package/meteora.md) latest

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 0.1.8 (latest) — 2022-05-26
- 0.1.7 — 2021-07-14
- 0.1.6 — 2021-07-14
- 0.1.5 — 2021-06-10
- 0.1.4 — 2021-05-12
- 0.1.3 — 2021-04-29
- 0.1.2 — 2021-04-28
- 0.1.1 — 2021-04-28
- 0.1.0 — 2021-04-28
- 0.0.2 — 2021-04-18
- 0.0.1 — 2021-04-18
- 0.0.0 — 2021-04-18

## README

# 🧙‍♀️ Magic Scrolls 📜

An easy to use scroll based tweening class.
Any element can be tweened by a percentage based on how far through the chosen element we have scrolled.
The class will handle the tweening, you do the rest!

## 📚 Features

#### Scroll Based Animations
For simple, non scroll based tweening, check out [Tween](https://www.npmjs.com/package/@meteora-digital/tween);

| Feature | Support |
|---------|---------|
| Tweening | ✔️ |
| Parallax | ✔️ |


## 🪄 Installation

with webpack

```bash
yarn add magic-scrolls
```

## 🧪 Usage

```html
<section class="banner">
	<div class="banner__image" style="background-image: url('path/to/your/image.jpg');"></div>
</section>
```

```javascript
import MagicScrolls from 'magic-scrolls';

const banner = document.querySelector('.banner');
const image = document.querySelector('.banner__image');
```

## ⚗️ The Magic

#### Create a Magic Scroll!

| Option | Type | Description |
|--------|------|-------------|
| duration | number | number in milliseconds for how long the tween should take to complete | 
| fps | number | The frames per second for the animation | 

```javascript
const magic = new MagicScrolls(banner, {
	duration: 500,
	fps: 60,
});
```

#### Tweening

Use tweening to smoothly animate an element's styles based on your scroll position within the Magic Scroll element!

```javascript
magic.tween(image, (percentage) => {
	image.style.transform = `translateX(${percentage}%)`;
});
```

#### Parallax

Parallax is a powerful spell which will move your elements for you.

The image will move precisely within the parent element as a percentage of it's height within the container.
You will never see white space and can control the movement simply by changing it's height.

```scss
.banner {
	position: relative;
	height: 1000px;
	overflow: hidden;

	&__image {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 130%;
	}
}
```

```javascript
magic.parallax(image);
```

## License
[MIT](https://choosealicense.com/licenses/mit/)

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