All Projects → ChrisCavs → Rallax.js

ChrisCavs / Rallax.js

Licence: mit
Dead simple parallax scrolling.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Rallax.js

universal-parallax
Easy parallax plugin using pure javascript. Also works on mobile platforms. Cross browser support.
Stars: ✭ 107 (-92.57%)
Mutual labels:  parallax, vanilla-javascript, parallax-scrolling
Perspective
🖼Parallax scrolling effect. And more.
Stars: ✭ 80 (-94.45%)
Mutual labels:  parallax, vanilla-javascript, parallax-scrolling
Bs Stepper
A stepper for Bootstrap 4.x
Stars: ✭ 261 (-81.89%)
Mutual labels:  vanilla-js, vanilla-javascript
Vanillajs Spa
a simple SPA in vanilla js
Stars: ✭ 265 (-81.61%)
Mutual labels:  vanilla-js, vanilla-javascript
Darkmode Js
DarkModeJS helps you to auto detect user's time and switch theme to darkside
Stars: ✭ 328 (-77.24%)
Mutual labels:  vanilla-js, vanilla-javascript
Vanilla Semantic Ui
Semantic UI component framework without jQuery
Stars: ✭ 97 (-93.27%)
Mutual labels:  vanilla-js, vanilla-javascript
pAppwords
Vanilla JS plug-in with zero configuration integrate with HaveIBeenPwned API v2
Stars: ✭ 21 (-98.54%)
Mutual labels:  vanilla-javascript, vanilla-js
Vanilla Datatables
A lightweight, dependency-free javascript HTML table plugin
Stars: ✭ 314 (-78.21%)
Mutual labels:  vanilla-js, vanilla-javascript
vanilla-js-drawer
A dependency-free Vanilla JS drawer. No dependencies, no automation build tools.
Stars: ✭ 20 (-98.61%)
Mutual labels:  vanilla-javascript, vanilla-js
Learn Vanilla Js
Open source list of paid & free resources to learn vanilla JavaScript
Stars: ✭ 945 (-34.42%)
Mutual labels:  vanilla-js, vanilla-javascript
Vanilla Lazyload
LazyLoad is a lightweight, flexible script that speeds up your website by deferring the loading of your below-the-fold images, backgrounds, videos, iframes and scripts to when they will enter the viewport. Written in plain "vanilla" JavaScript, it leverages IntersectionObserver, supports responsive images and enables native lazy loading.
Stars: ✭ 6,596 (+357.74%)
Mutual labels:  vanilla-js, vanilla-javascript
Vanilla Ui Router
Simple vanilla JavaScript router
Stars: ✭ 42 (-97.09%)
Mutual labels:  vanilla-js, vanilla-javascript
vanillajs-hello
Start a VanillaJS website using WebPack in just 30 seconds: HTML,CSS,Babel,SASS,Bootstrap,Prettier,Gitpod
Stars: ✭ 24 (-98.33%)
Mutual labels:  vanilla-javascript, vanilla-js
spider-covid-19-viz-3d
Speedy access to the latest, local COVID-19 data with a familiar interface: the Globe
Stars: ✭ 19 (-98.68%)
Mutual labels:  vanilla-javascript, vanilla-js
tabbis.js
Pure vanilla javascript tabs with nesting
Stars: ✭ 44 (-96.95%)
Mutual labels:  vanilla-javascript, vanilla-js
Selectr
A lightweight, vanilla javascript select box replacement. No dependencies.
Stars: ✭ 293 (-79.67%)
Mutual labels:  vanilla-js, vanilla-javascript
Bin
A tiny (<1kb) localStorage and sessionStorage helper library.
Stars: ✭ 70 (-95.14%)
Mutual labels:  vanilla-js, vanilla-javascript
bs-breakpoints
A plugin which detect Bootstrap 4 breakpoints and emit when there is a change
Stars: ✭ 22 (-98.47%)
Mutual labels:  vanilla-javascript, vanilla-js
react-rellax
React Parallax component using Rellax.js
Stars: ✭ 39 (-97.29%)
Mutual labels:  parallax, parallax-scrolling
Bunny
BunnyJS - Lightweight native (vanilla) JavaScript (JS) and ECMAScript 6 (ES6) browser library, package of small stand-alone components without dependencies: FormData, upload, image preview, HTML5 validation, Autocomplete, Dropdown, Calendar, Datepicker, Ajax, Datatable, Pagination, URL, Template engine, Element positioning, smooth scrolling, routing, inversion of control and more. Simple syntax and architecture. Next generation jQuery and front-end framework. Documentation and examples available.
Stars: ✭ 473 (-67.18%)
Mutual labels:  vanilla-js, vanilla-javascript

Rallax.js

rallax.js on NPM

Dead-simple parallax scrolling.

See a demo.

Usage

Follow these steps to get started:

  1. Overview
  2. Install
  3. Call
  4. Review Options
  5. Review API
  6. Handling Page Refresh

Overview

Want to create dynamic parallax scrolling effects on your web page, without relying on jQuery?

Rallax.js makes it easy to create a parallax effect on a target HTML element, with great performance and a robust API. Make either a basic scrolling parallax, or change it up with automatic callbacks (when method), start/stop, speed changes, and mobile handling.

Install

Using NPM, install Rallax, and save it to your package.json dependencies.

$ npm install rallax.js --save

Then, import Rallax, naming it according to your preference.

import rallax from 'rallax.js'

Call

To generate the desired effect, call Rallax, passing in your element/target-selector and your desired options.

const options = { speed: 0.4 }
const parallax = rallax('.parallax', options)

// or:

const target = document.querySelector('.parallax')
const parallax = rallax(target, { speed: 0.4 })

Note: Rallax.js does not make any assumptions regarding the styling of the target element.

Options

You are not required to pass any options. All options come with sensible defaults, shown below:

{
  speed: 0.3,
  mobilePx: false
}

Explanation of each option follows:

speed

Accepts a float number.

At a speed of 0, the target will scroll like a static element. At a speed of 1, the target will appear fixed (will move at the speed of scroll). At even higher speeds, the target will move quicker than the speed of scroll.

mobilePx

Accepts an integer, as number of pixels.

Pass this option if you want parallax for this target to automatically be disabled at a certain screen width.

API

Calling Rallax will return an object with a set of methods defined. Those methods are:

stop

Calling stop() will pause the parallax effect on the target until the next time you call start().

const parallax = rallax('.parallax')

if (condition) {
  parallax.stop()
}

start

Calling start() will re-enable the parallax effect if you had previously disabled it. Note: calling start() will not re-enable the effect if you have disabled it with the mobilePx option.

const parallax = rallax('.parallax')
parallax.stop()

// some time later

parallax.start()

getSpeed

Returns the current speed of the target.

changeSpeed (speed)

Accepts a float.

Calling changeSpeed will change the speed of the target parallax effect.

// initialize the target at a speed of 0.6
const parallax = rallax('.parallax', { speed: 0.6 })

// change speed to 1, making the target appear fixed
parallax.changeSpeed(1)

when (condition, action)

Accepts a condition function and an action function.

Calling when will queue a condition and action onto the target, which will be evaluated before the target is scrolled. The when method is useful for setting up all kinds of special effects.

when methods can be chained together.

const parallax = rallax('.parallax')

// after reaching a certain position in the document, 
// increase the target's speed
parallax.when(
  () => window.scrollY > 400,
  () => parallax.changeSpeed(1)
)

// stop the parallax after a certain period of time
const startTime = new Date().getTime()

parallax.when(
  () => {
    const newTime = new Date().getTime()
    return newTime - startTime > 4000
  },
  () => parallax.stop()
)

Handling Page Refresh

Rallax.js will adapt to the refreshing of the page, and place targets where they would be normally if they were to scroll to the point of refresh.

However, if using changeSpeed in conjunction with when methods/conditionals, it's important to scroll to the top of the page when the user refreshes. Code to handle such a situation:

window.onbeforeunload = () => {
  window.scrollTo(0, 0)
  // alternatively, you can put an animation function here
  // that will bring user to the top of page
}

Browser Support

Rallax depends on the following browser APIs:

Consequently, it supports the following natively:

  • Chrome 24+
  • Firefox 23+
  • Safari 6.1+
  • Opera 15+
  • IE 10+
  • iOS Safari 7.1+

License

MIT. © 2018 Christopher Cavalea

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].