0.1.8 โ€ข Published 2 years ago

magic-scrolls v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

๐Ÿง™โ€โ™€๏ธ 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;

FeatureSupport
Tweeningโœ”๏ธ
Parallaxโœ”๏ธ

๐Ÿช„ Installation

with webpack

yarn add magic-scrolls

๐Ÿงช Usage

<section class="banner">
	<div class="banner__image" style="background-image: url('path/to/your/image.jpg');"></div>
</section>
import MagicScrolls from 'magic-scrolls';

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

โš—๏ธ The Magic

Create a Magic Scroll!

OptionTypeDescription
durationnumbernumber in milliseconds for how long the tween should take to complete
fpsnumberThe frames per second for the animation
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!

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.

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

	&__image {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 130%;
	}
}
magic.parallax(image);

License

MIT

0.1.8

2 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago