jParallax: jQuery plugin for creating interactive parallax effect

What does jquery.parallax do?

jParallax turns nodes into absolutely positioned layers that move in response to the mouse. Depending on their dimensions these layers move at different rates, in a parallaxy kind of way.

With a bit of CSS you can either set up windows to see these layers through, or leave them free to roam about.

Using jParallax

The default behaviour of jParallax is to show the whole width of a layer in response to the mouse travelling the whole width of the mouseport. When the mouse is moved to the extreme left-hand side of the mouseport the left-hand side of the layer meets the left-hand side of its viewport, and when the mouse is moved to the extreme right-hand side of the mouseport the right-hand side of the layer arrives at the right hand-side of its viewport.

Therefore, the simplest way to use jParallax is to make the layers different sizes using CSS. Bigger layers move faster (and thus appear closer), and unless a layer is smaller than the viewport, its edges are never seen. The Colour Drops Demo is made in exactly this way, with jParallax in its default state, and the ‘speed’ of the layers controlled simply by making the images different sizes. Only the mouseport option is defined, to make it the same as the viewport.

jParallax CSS

To know all about CSS implementation, please go to jParallax homepage

There are various ways to style jParallax effectively. The classic approach is the ‘viewport’ effect, as in this example. To see layers through a viewport, wrap them in a container with a style similar to:

.parallax-viewport {
  position:relative; overflow:hidden; width:npx; height:npx;
 }

Download: https://github.com/stephband/jparallax

Demonstration: https://stephen.band/jparallax/

Plugin homepage: https://stephen.band/jparallax/

Implementation:

1. First, include CSS & jQuery files

<!-- CSS -->
<link rel="stylesheet" href="jquery.parallax.css" />
 
<!-- jQuery files -->
<script src="jquery.min.js"></script>
<script src="jquery.parallax.min.js"></script>

2. HTML code

<ul>
  <li class="parallax-layer"></li>
  <li class="parallax-layer"></li>
</ul>

3. jParallax plugin call

jQuery(document).ready(function(){
  // Declare parallax on layers
  jQuery('.parallax-layer').parallax({
  mouseport: jQuery("#port")
  });
});
</script>

Options:

mouseportObjectDefault : jQuery(document) – Identifies DOM node to track the mouse in.
xparallaxBooleanDefault true – Set to true or false to enable or disable movement. boolean I 0-1 | ‘n%’ I ‘npx’
yparallaxBooleanDefault : true – Set to true or false to enable or disable movement. boolean I 0-1 I ‘n%’ I ‘npx’
xoriginIntegerDefault : 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. 0-1 I ‘n%’ I ‘left’, ‘center’, ‘middle’, ‘right’
yoriginIntegerDefault : 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 0-1 I ‘n%’ I ‘left”, ‘center’, ‘middle’, ‘right’
freezeClassStringDefault “Freeze” – Class set on a layer when it is frozen.
decayIntegerDefault : 0.66 – Sets the rate at which the layers ‘catch up’ with the mouse position. 0 is instantly, 1 is forever.
frameDurationIntegerDefault : 30 – (milliseconds) Length of time between animation frames.
widthIntegerDefault: undefined – (pixels) 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.
heightIntegerDefault : undefined – (pixels) 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.

Methods:

triggerFunctionEvents can be triggered on layers using jQuery’s trigger method : jQuery(‘.parallax-layer’) .trigger(‘freeze or ‘unfreeze”);

Screenshots:

Creating a JavaScript Library

I recently wrote a JavaScript library for creating random colors and color schemes, and while I foun…

s3Slider jQuery Plugin & Tutorial

The s3Slider jQuery plugin is made by example of jd`s smooth slide show script. Usage: HTML: Sample …

jQuery Optimization: Avoid Unnecessary Selector

Common subexpression elimination is a common way to optimize any programming code. Doing unnecessary…

Fading Links Using jQuery: dwFadingLinks

Earlier this month, we posted a MooTools script that faded links to and from a color during the mous…

jQuery Flash Plugin

This jQuery plugin is for embedding Flash movies. Pages are progressively enhanced when Flash and Ja…

jQuery Optimization: Optimize Selector

We can also optimize our selector other than being a bit specific on our selector. The key to optimi…

jQuery drop down menu: droppy

Quick and dirty nested drop-down menu in the jQuery style. I needed a nav like this for a recent pro…