npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parallax-imagescroll

v0.2.3

Published

Parallax ImageScroll is a simple and easy jQuery plugin for creating image parallax effects when scrolling the page, inspired by Spotify.com.

Downloads

175

Readme

Parallax ImageScroll - jQuery plugin

JQuery and amd compatible plugin to create a parallax effect with images. Heavily inspired by the spotify.com website.

The plugin is really simple to use with some options to tweek. It makes use of css3 transform for animation where supported and falls back to top and left positioning for ancient browsers.

Check out the live demo. (No parallax effect and smaller image sizes for touch devices, see Touch section for details.)

Markup

Markup can consist of as many image elements as you want, but you should separate them with a content block, e.g. a section.

<div class="img-holder" data-image="anImage.jpg"></div>
<section><p>Content that "slides" on top of the images</p></section>
<div class="img-holder" data-image="anotherImage.jpg">[optional content to be displayed on top of the images]</div>

You can set parameters using html5 data attributes or with javascript, see options section for details.

Initialization

To initialize the plugin, call the imageScroll method on your image elements

$('.img-holder').imageScroll();

AMD

The plugin is AMD compatible. To use with e.g. RequireJS, you can do this. See demo files for example.

require(['jquery.imageScroll'], function (ImageScroll) {
    $('.img-holder').each(function () {
        new ImageScroll(this);
    });
    //or
    //$('.img-holder').imageScroll();
});

Options

You can configure the default options, by passing an option object to the plugin

$('.img-holder').imageScroll({
    coverRatio: 0.5
});

or set the options via data attributes, data-optionname (available options: image, width (mediaWidth), height (mediaHeight), cover-ratio (coverRatio), min-height (holderMinHeight), max-height (holderMaxHeight), extra-height (extraHeight)

<div class="img-holder" data-image="anImage.jpg" data-cover-ratio="0.5"></div>

or set the options globally

$.fn.imageScroll.defaults.coverRatio = 0.5;
//AMD
ImageScroll.defaults.coverRatio = 0.5;

Configurable options:

  • image: null : The image to show (best to set this option via data attr (data-img)
  • imageAttribute: 'image': The data attribute name for images. Uses the value of this attribute to load the image
  • container: $('body') The element to which the parallax image(s) will be attached to
  • windowObject: $(window) The window object which listens to scroll and resize events
  • speed: 0.2 The speed of the parallax effect. A floating number between 0 and 1, where a higher number will move the images faster upwards
  • coverRatio: 0.75 //75% How many percent of the screen each image should cover
  • holderClass: 'imageHolder' Class added to the image holder(s)
  • imgClass: 'img-holder-img' Class added to the image
  • holderMinHeight: 200 The minimum height of the image in pixels
  • holderMaxHeight: null The maximum height of the image in pixels
  • extraHeight: 0 Extra height added to the image. Can be useful if you want to show more of the top image
  • mediaWidth: 1600 The original width of the image
  • mediaHeight: 900 The original height of the image
  • parallax: true Whether or not you want the parallax effect, e.g. does not work very well in ancient browsers
  • touch: false Presents a mobile/tablet friendy version, no parallax effect and smaller images (should be used with a mobile/tablet optimized images)

Public methods:

  • disable()
  • enable()
  • refresh()
  • destroy()

You can call them on individual- or all the instances.

//Call method refresh on all the instances of the plugin
var instances = $('.img-holder');
instances.imageScroll('refresh');

//E.g. Call method refresh on the first image
//Alternative 1:
var instances = $('.img-holder');
var instance = $(instances.get(0));
instance.imageScroll('refresh');

//Alternative 2:
var instances = $('.img-holder');
var instance = $(instances.get(0)).data('plugin_imageScroll');
instance.refresh();

Touch

The effect is not very smooth on a touch device. You could therefore present the user with a fallback version, which displays the images with no parallax effect. You can do so by checking for touch (e.g. with Modernizr, external lib) and set dynamic options to adjust to this.

var touch = Modernizr.touch;
$('.img-holder').imageScroll({
    imageAttribute: (touch === true) ? 'image-mobile' : 'image',
    touch: touch
});

Installation

Install using bower

bower install Parallax-ImageScroll

Install using npm

npm install parallax-imagescroll

Requirements

jQuery version 1.8.0 or higher

Notes

If you add content on top of the parallaxed image, make sure to apply a higher z-depth for the content (applies for browsers that support 3d transforms). Example:

<div class="img-holder" data-image="anotherImage.jpg"><p style="-webkit-transform: translateZ(1px)">Hello world!</p></div>

Limitations

Does not work very well on mobile or IE <= 9. You can then present a fallback solution by disabling parallax for ancient desktop browser (set parallax option to false) and present touch optimized images for touch devices (set touch option to true).

MIT

MIT licensed