Multi Layer Smooth Parallax Animation Plugin – jparallax

Looking for a affordable website?

GET STARTED
www.codingexpertz.com
Multi Layer Smooth Parallax Animation Plugin – jparallax

File Size: 2193KB

Total Views: 1148

Date Created:

Last Modified Date:

Official Website: Go to website

License:

Jparallax is a parallax animation plugin library that creates a smooth animation effect within multiple positioned layers according to your needs. Depending on their dimensions each of the layers move at different rates and axis. You can set the movement of the parallax axis to horizontally or vertically as you need. There are various options to customize the parallax effect, position or axis.

Features:

  • Multilayered supported.
  • Creates smooth parallax animation.
  • Supported on all modern browsers.
  • Can modify the layer position with the help of CSS.

How to use it:

1. Include the Javascript jquery.event.frame.js and jquery.parallax.min.js at the bottom of the web page.

<script src="path/to/jquery.event.frame.js"></script>
<script src="path/to/jquery.parallax.min.js"></script>

2. Include the CSS jquery.parallax.css in the header of the page.

<link rel="stylesheet" href="path/to/jquery.parallax.css">

3. Add the basic HTML to the page.

<div class="parallax-viewport" id="parallax">
  <div class="parallax-layer">
    <img src="path/to/img-1" alt=""/>
  </div>
  <div class="parallax-layer">
    <img src="path/to/img-2" alt=""/>
  </div>
</div>

4. Add some custom CSS to position the parallax layer, for reference you can visit the demo page.

5. Initialize the plugin and we’re ready to go.

jQuery(window).load(function() {
  jQuery('#parallax .parallax-layer')
  .parallax({
    mouseport: jQuery('#parallax')
  });
});

Plugin’s default options:

Option Type Default
mouseport selector string | jQuery object jQuery(document)
Identifies DOM node to track the mouse in.
xparallax boolean | 0-1 | ‘n%’ | ‘npx’ true
yparallax boolean | 0-1 | ‘n%’ | ‘npx’ true
Set to true or false to enable or disable movement. Alternatively, to control the range over which a layer travels, either pass in an absolute value in pixels, or a scaling factor in the range 0-1 (scaling factors can also be expressed as percentage strings). Scaling factors outside this range are also accepted, but be aware that factors below 0 (or ‘0%’) will reverse the direction of travel, and greater than 1 (or ‘100%’) will make layer edges appear inside the extremes of the viewport.
xorigin 0-1 | ‘n%’ | ‘left’, ‘center’, ‘middle’, ‘right’ 0.5
yorigin 0-1 | ‘n%’ | ‘top’, ‘center’, ‘middle’. ‘bottom’ 0.5
Only meaningful when xparallax or yparallax are not 1. Determines which point of the layer lines up with which point of the viewport when the mouse is at that point in the mouseport. Got that?

It’s easy really. It’s the same behaviour as the css property background-position. If xorigin is set to 0 (or ‘left’), then when the mouse is moved to the left hand side of the mouseport the left hand side of the layer arrives at the left hand side of the viewport. If it’s set to 0.5 (or ‘center’), then when the mouse is at the centre of the mouseport the centre of the layer is aligned with the centre of the viewport. And similarly with 1 (or ‘right’).

Numbers outside the range 0-1 may also be used.

freezeClass string ‘freeze’
Class set on a layer when it is frozen.
decay 0-1 0.66
Sets the rate at which the layers ‘catch up’ with the mouse position. 0 is instantly, 1 is forever.
frameDuration int (milliseconds) 30
Length of time between animation frames. With a lot of big layers, you may want to increase the frame duration to save CPU. About 50 is acceptable (20 frames/second), but I like it zippy. Modern browsers like Google Chrome have really accurate timing, but many older browsers choke below about 15ms.
width int (px) undefined
height int (px) undefined
Values for layer dimensions, normally read from css, can be overridden. This does NOT change the size of the layer, only jParallax’s idea of how big it is. This can be very useful in cases where you want to be able to ‘click through’ the upper layers. Typically you make layers very small in css, but tell jParallax they are big via the width and height options.

Leave a comment

Your email address will not be published. Required fields are marked *

STAYUPDATED

Receive all our future posts instantly in your inbox. Enter your email to enroll.