1.3.2 • Published 5 years ago

universal-parallax v1.3.2

Weekly downloads
52
License
MIT
Repository
github
Last release
5 years ago

npm version Package Quality npm.io npm.io

Universal Parallax

Easy parallax plugin using pure javascript. Lightweight (2kb) and cross browser compatibility - including mobile platforms (iOS, Android).

See demo

:zap: Features

  • Easy setup
  • Pure JavaScript
  • Adaptive height
  • Works on mobile devices
  • Lightweight (2kb minified)

:floppy_disk: Install

$ npm i universal-parallax -S

:rocket: Setup

#1

Choose between:

  • Include this in your <head> section
<link href="node_modules/universal-parallax/dist/universal-parallax.min.css" rel="stylesheet">
  • Or add this CSS
.parallax__container {
	clip: rect(0, auto, auto, 0);
	height: 100%;
	left: 0;
	overflow: hidden;
	position: absolute;
	top: 0;
	width: 100%;
	z-index: -100;
}

.parallax {
	position: fixed;
	top: 0;
	-webkit-transform: translate3d(0, 0, 0);
	transform: translate3d(0, 0, 0);
	-webkit-transform-style: preserve-3d;
	transform-style: preserve-3d;
	width: 100%;

	/* BG behaviour */
	background-position: center;
	background-repeat: no-repeat;
	background-size: cover;
}

:zap: BG behaviour in seperate class gives more flexibility controlling them :zap: SASS version available in /dist folder

#2

If <section> is your container, make the parallax element inside it

<section>
	<div class="parallax" data-parallax-image="path/to/your_image">
</section>

:zap: You can also use background-image to define your image instead of using data-parallax-image=""

#3

Include the script to your project

<script src="node_modules/universal-parallax/dist/universal-parallax.min.js"></script>

#4

Initialize the JS function

<script>
	new universalParallax().init();
</script>

That's it! :checkered_flag:

Custom speed

You can change the parallax speed; the higher the number, the slower the parallax effect

new universalParallax().init({
	speed: 6.0
});

:zap: speed: 1 is the minimum value before the background image is fixed

Tips

Opacity

If you want your backround color to shine through or dampen the image without making it a .png - just add transparency to it

.parallax {
	opacity: 0.5;
}
1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago