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

parallaxbro

v0.1.4

Published

A powerful JS parallax framework

Downloads

10

Readme

ParallaxBro

const ParallaxBro = require('parallaxbro');
const laxbro = new ParallaxBro('#wrapper', '2000px');

const c1 = laxbro.addCollection('#collection1');

c1.addElements({
  '#element1': {
    top: 100, // All position values are assumed to be in px.
    hide: {0: false, 500: true}, // Will hide once window.pageYOffset ≈ 500px.
    center: true, // Applies 'margin: 0 auto'
    speed: {
      0: 1, // Speed 1 is normal scrolling rate.
      500: 0, // Speed 0 will stop the element from scrolling.
      1000: -1, // Negative values scroll the element in reverse.
    }
    zIndex: -1, // -1 is default zIndex for all elements.
    update: {
      0: ($el, posY) => $el.fadeOut(), // $el is jQuery wrapped element.
      1000: ($el, posY) => $el.fadeIn(), // Called when window.pageYOffset ≈ 1000.
    },
    xFunc: (posY) => posY, // Changes the element's x position.
  },
  '#element2': { /* ... */ }
});

Installing

Npm:

npm i --save parallaxbro

Manually:

Find the library at: ./dist/index.js and ./dist/index.min.js

* jQuery is a required dependency

Demo

https://iamdevonbutler.github.io/parallaxbro/

See App.js to view the demo's parallaxbro config.

Collections and elements

Parallax elements are grouped into collections. A collection is a convenient way to apply behaviors to a group of elements. Properties such as: top, and hide, are applied to all elements in a collection. Collections are a useful in the development of parallax designs; for instance, they offer a convenient way to either hide or position sections of your content.

Multi parameter objects

In the example above, the hide and speed options accept both simple Boolean / Number values or a keyed object. The object keys, we call them breakpoints, change the behavior of your program when the pageYOffset position is == the breakpoint. Object values for options can be passed to both collections and elements.

c1.addElement('#wrapper', {
  top: {
    0: 0,
    500: 100,
    1000: 1000,
  },
  hide: {
    0: false,
    1500: true,
  }
})

The speed option

Setting the speed option to 1 will have no effect on the element. It will scroll w/ the page per normal.

Setting the speed option to a negative value will move the element in the reverse direction.

Setting the speed option to 0 will freeze the element on the page.

Custom updates

Leverage the update option to preform updates of any sort at specific breakpoints:

const c1 = require('./collection');

c1.addElements('#element1', {
 /**
  * @param {Object} $el - element wrapped in jQuery
  * @param {Number} posY
  * @this - the parallax element.
  */
  update: {
    0: ($el, posY) => $el.fadeOut()
    200: ($el, posY) => $el.fadeIn()
  }
});

xFunc

The xFunc option for parallax elements allows you to move elements on the x-axis in addition to the y-axis.

const c1 = require('./collection');

c1.addElements('#element1', {
   /**
    * @param {Number} posY
    */     
    xFunc: {
      1200: (posY) => -posY
    },
});

The callback is passed posY (pageYOffset - breakpoint), and the function should return the element's new x position.

Debug mode

Pass the option debug=true to add a window.pageYOffset indicator to the page.

API

ParallaxBro(selector, height, [options]) - constructor.

@param {String} selector

Selector string of the wrapper element.

@param {Number} height

Static height of the parallax page. It's useful to set it to a large number in development and change it once your design is completed.

@param {Object} [options]

  • debug {Boolean} - adds a debugger to the page.
  • disableStyles {Boolean} - disable ParallaxBro default page styling.
  • height {String} - parallax page height.

.addCollection(selector, [options])

const ParallaxBro = require('parallaxbro');
const laxbro = new ParallaxBro('#wrapper');

const c1 = laxbro.addCollection('#collection1', {});

@param {String} selector Selector string of the collection wrapper element.

@param {Object} [options]

Options include:

  • top {Number|Object}
  • hide {Boolean|Object}
  • zIndex {Number|Object}
  • update {Object}

.addElements(obj)

const c1 = require('./collection');

c1.addElements({
  '#elementSelector': { /* options */ },
  '#elementSelector2': { /* options */ },
});

@param {Object} options

Options include:

  • top {Number|Object}
  • hide {Boolean|Object}
  • speed {Number|Object}
  • center {Boolean|Object}
  • zIndex {Number|Object}
  • update {Object}
  • xFunc {Function|Object}

.addElement(selector, obj)

const c1 = require('./collection');

c1.addElement('#elementSelector', {
  /* options */
});

@param {String} selector

Selector string of the element.

@param {Object} options

Options are the same as .addElements()

.unbind()

Unbinds Parallaxbro from requestAnimationFrame recused loop.