Coder Social home page Coder Social logo

rellax's Introduction

RELLAX

NPM Package Minified Size Gzipped Size

Rellax is a buttery smooth, super lightweight, vanilla javascript parallax library. Update: Rellax now works on mobile (v1.0.0).

Getting Started

Using npm

npm install rellax --save

Using yarn

yarn add rellax

CDN

<script src="https://cdn.jsdelivr.net/gh/dixonandmoe/rellax@master/rellax.min.js"></script>

Download Locally

if you're old school like us download and insert rellax.min.js in your html

<div class="rellax">
  I’m that default chill speed of "-2"
</div>
<div class="rellax" data-rellax-speed="7">
  I’m super fast!!
</div>
<div class="rellax" data-rellax-speed="-4">
  I’m extra slow and smooth
</div>

<script src="https://cdn.jsdelivr.net/gh/dixonandmoe/rellax@master/rellax.min.js"></script>
<script>
  // Accepts any class name
  var rellax = new Rellax('.rellax');
</script>
<script>
  // Also can pass in optional settings block
  var rellax = new Rellax('.rellax', {
    speed: -2,
    center: false,
    wrapper: null,
    round: true,
    vertical: true,
    horizontal: false
  });
</script>

Features

Speed

Use the data-rellax-speed attribute to set the speed of a .rellax element to something other than the default value (which is -2). A negative value will make it move slower than regular scrolling, and a positive value will make it move faster. We recommend keeping the speed between -10 and 10.

Responsive Speed

Use responsive speed attributes for breakpoint levels that require a different speed. Defaults to the data-rellax-speed setting in unspecified breakpoints.

<div class="rellax" data-rellax-speed="7" data-rellax-xs-speed="-5" data-rellax-mobile-speed="3" data-rellax-tablet-speed="-8" data-rellax-desktop-speed="1">
  I parallax at all different speeds depending on your screen width.
</div>

Pass an array of breakpoints. Each breakpoint value represents the resolution for mobile, tablet, desktop respectively. Checkout the responsiveness of the demo

<script>
  // This is the default setting
  var rellax = new Rellax('.rellax', {
    breakpoints: [576, 768, 1201]
  });
</script>

Centering

After some fantastic work from @p-realinho, we just released the ability to center parallax elements in your viewport! We'll be building a nice demo website, but for now check out the tests folder for several examples of how it works.

There's two ways to implement centering, either on specific elements or as a global option.

  1. Element-wise Centering

  • Add the data-rellax-percentage="0.5" to a specific html element
<div class="rellax" data-rellax-percentage="0.5">
  I’m that default chill speed of "-2" and "centered"
</div>
<div class="rellax" data-rellax-speed="7" data-rellax-percentage="0.5">
  I’m super fast!! And super centered!!
</div>
<div class="rellax" data-rellax-speed="-4" data-rellax-percentage="0.5">
  I’m extra slow and smooth, and hella centered.
</div>
  1. Global Centering

  • To activate the center feature in your whole html, add the code your <script> tag or JS file:
<script>
  // Center all the things!
  var rellax = new Rellax('.rellax', {
    center: true
  });
</script>

Z-index

If you want to sort your elements properly in the Z space, you can use the data-rellax-zindex property

<div class="rellax">
  I’m that default chill speed of "-2" and default z-index of 0
</div>
<div class="rellax" data-rellax-speed="7" data-rellax-zindex="5">
  I’m super fast!! And on top of the previous element, I'm z-index 5!!
</div>

Horizontal Parallax

Horizontal parallax is disabled by default. You can enable it by passing horizontal: true in the settings block. This feature is intended for panoramic style websites, where users scroll horizontally instead of vertically. Note that this can work together at the same time with the default vertical parallax. If you do not want this, pass vertical: false in the settings block.

<script>
  // Adding horizantal parallax scrolling
  var rellax = new Rellax('.rellax', {
    // Activate horizantal scrolling
    // Turned off by default
    horizontal: true
    //Deactivate vertical scrolling
    vertical: false
  });
</script>

Custom Wrapper

By default, the position of parallax elements is determined via the scroll position of the body. Passing in the wrapper property will tell Rellax to watch that element instead.

<script>
  // Set wrapper to .custom-element instead of the body
  var rellax = new Rellax('.rellax', {
    wrapper: '.custom-element'
  });
</script>

Refresh

<script>
  // Start Rellax
  var rellax = new Rellax('.rellax');

  // Destroy and create again parallax with previous settings
  rellax.refresh();
</script>

Destroy

<script>
  // Start Rellax
  var rellax = new Rellax('.rellax');

  // End Rellax and reset parallax elements to their original positions
  rellax.destroy();
</script>

Callback

<script>
  // Start Rellax
  var rellax = new Rellax('.rellax-blur-card', {
    callback: function(positions) {
      // callback every position change
      console.log(positions);
    }
  });
</script>

Target node

Instead of using a className you can use a node, handy when using React and you want to use refs instead of className.

<div ref={ref => { this.rellaxRef = ref }}>
  I’m that default chill speed of "-2"
</div>

var rellax = new Rellax(this.rellaxRef)

In the Wild

If you're using Rellax in production, we'd love to list you here! Let us know: [email protected]

Development

In the spirit of lightweight javascript, the build processes (thus far) is lightweight also.

  1. Open demo.html
  2. Make code changes and refresh browser
  3. Once feature is finished or bug fixed, use jshint to lint code
  4. Fix lint issues then use Google Closure Compiler to minify
  5. 🍻

Changelog

  • 1.7.1: Remove animation on destory PR
  • 1.7.0: Scroll position set relative to the wrapper PR

rellax's People

Contributors

ac-awhite avatar ajimix avatar amdixon avatar ashfahan avatar benface avatar bharatramnani94 avatar colega avatar connor-baer avatar gavrochelegnou avatar glafarge avatar imcodingideas avatar kajetan-nobel avatar kant avatar kloo012 avatar kruemelkatze avatar maximebonhomme avatar moeamaya avatar mul-lunarway avatar nlemoine avatar olegtsaplin avatar p-realinho avatar rodrickcalvin avatar shrpne avatar susonwaiba avatar terwanerik avatar tgcnzn avatar timgates42 avatar wyyz514 avatar yuanchuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rellax's Issues

DEBUG is not defined

Is there a way to prevent this error in the console? Do I just need to create a global DEBUG variable?

Option to disable on mobile?

Hi. Love this library on desktop. But in general I hate parallax on mobile devices due to wierd browser address bar behavior. Is there any tips how to disable rellax on mobile? I could detect mobile devices, but what next?

page hard refresh

Browser: firefox
when page is refreshed with CTRL+F5 or CTRL+SHIFT+R

element that has parallax effect changes position

example here: http://www.iambailon.com/

same thing happens with my page
default
2

"Percentage" positioning doesn't work on Firefox and IE when initial page scroll is not 0

First of all - thanks for a wonderfull library!

While developing on Chrome everything worked perfectly but then, when I tried to run the project on Firefox or IE an issue came up.

I'm using "center: true" setting and it seems that it calculates the positions correctly only if the page is loaded while beeing on top of the page.
If I'm somewhere lower on the page and hit refresh button - the positions are completely miscalculated.

It's easy to reproduce by running one of the tests - 'tests/percentage.html' - on Firefox, scrolling down a bit and hitting "F5".

Please let me know what can I do to fix this issue.
Currently - it completely brakes my project and if it's an unfixable issue - I'll have to resign from using rellax (which I would not like to).

Thanks!

Semantic Versioning

It would be great if version numbers would be used to reflect changes in the repo.

Right now all files including the readme still say "version 1.0.0" though the repo has had quite some changes since the release of the "original version 1.0.0" - using semantic versioning (along with github releases/tags) would be super helpful!

stop translating when element is out of view

Hi.
Would it be possible to stop the element from translating when it moves out of view?
at the moment elements out of view are still translating as you scroll down your page.

Cheers,
Jack

Background Parallax Scroll?

Are you planning to implement background parallax? since the demo only show the implementation on an element postition.

Safari bug

In Safari (currently 10.0.2), the initial rellax element positions are incorrectly calculated unless a height is specified on the preceding containers/divs. Consequently, the 3d transforms are centered around a co-ordinate that is too far down the page. The more content is placed before the rellax element, the greater the error in the initial position. Testing in Chrome, the initial positions are calculated correctly.

I'm using the centering option var rellax = new Rellax('.rellax', {center: true});

Any ideas would be much appreciated.

Page scrolls beyond content

I configured Rellax on two elements: <body> which has an SVG texture for a background and a content div. When I add the .rellax class to the body, it doubles in height and creates a large area below the content.

What am I doing wrong??

Having problems getting rellax to do it's thing

I'm a designer learning code. Learning Wordpress also for some easy CMS integration, along with React etc. But current project is a simple Wordpress theme built from scratch. Trying to integrate rellax and having trouble getting it to work.

I got my css all fixed so that it should work with rellax properly (everything is flex display and relative positioning) and I've got wordpress properly bundling all my JS and importing it at the end of the but it doesn't appear to be running? I can confirm that script-production.js is including the rellax script

image

But from what I understand it doesn't seem to be applying the transform information in the way that it should. Like shouldn't it be injecting the divs with the rellax class some transform information or something, right? It's little unclear from the documentation

Here's a snippet of the code I'm working with:

 <section class="content">
        <p> <?php $field = 'case_study_intro_paragraph'; echo tag_stripped_field($field);  ?> </p>
    </section>
    <div class="image-divider rellax" data-rellax-speed="2" data-rellax-speed="4">
        <img class="image-divider rellax" data-rellax-speed="2" data-rellax-speed="4" src="https://s-media-cache-ak0.pinimg.com/564x/da/85/b3/da85b3fdcd43088765bcc70e757a0016.jpg">
    </div>

The php is just grabbing text from the database. I'm trying to have a static content paragraph object, interspersed with background image dividers. Also not sure if I'm supposed to put the rellax class on the img or the div containing it. I originally thought the div, but it doesn't seem to be working either way.

Also here's a view of the final static html
image

Also I the settings set down at the bottom script tag, as per documentation.

positioning working locally but not online

I have got a weird issue I can't figure out.

I have made this page:

Locally on chrome (running in browser-sync) the words "honesty", "integrity" & "delivery" are horizontally aligned in the centre of the page and has the effect I desire where the outside words swap positions as it scrolls.

When I upload it, the exact same page now the 3 words are not lined up in the middle of the page, they are lined up at the bottom of the page and stilted in middle of page.

To make it weirder in edge I get the correct effect that I get in chrome locally.

I grabbed the code from this repo in-case npm is old code but it didn't fix it.

Any idea what is going on?

Where can I find detailed documentation

Hey there, really great library but I'm wondering if there's documentation anywhere for the options I could pass to both the Rellax class and the data parameters. Looking at the source code I see that it supports such things as:

{ speed, center, round }
{ base, top, height, speed, style, transform }

But I couldn't find a description of what they mean (maybe I'm blind?). Regardless, it would be nice to see in table form in the readme.

Moreover, since we're passing some parameters as data values and some as options to the class, it should just be possible to pass these parameters either way. For example, center and round should be able to be passed via data properties and base, top, etc. should be able to be passed via options to the class. Data properties would simply override any "default" options specified in the options to the class.

new Rellax variable question

I want to create a widget for elementor with your parallax library . Elementor handle js files with scope
new Rellax accepts any class name and I need to base it on $scope variable. If I put var rellax = new Rellax(($scope.find('.rellax'))); it gives me an error cause it isn't a valid selector and if I just put var rellax = new Rellax('.rellax'); it doesn't find the class rellax. Is there a way to make it work ?

Add direction option

Maybe you could add an option for direction? Like optional direction=-1would reverse animations and direction=1would be default behaviour...

Parallax effect only for elements in viewport?

I am having a newsfeed with images+titles below them like Flipboard. I am applying the parallax effect to the images just like Flipboard app. And after trying many plugins, rellax is doing the best job for all its simplicity and lightweight.

But am wondering how to make the parallax effect run only when elements come into viewport. This will be helpful to make the effect more pronounced as right now at the default of -2 speed and 0.5 rellax percentage, the images in the bottom of the feed, when they come into the viewport, are way off from their respective titles.

iOS pull down / overscroll issue

When pulling down on the page on mobile iOS (overscroll?), the parallax motion can create an ugly gap below the element (eg if we are applying parallax to a hero banner) because we're scrolling in the opposite direction to usual.

We can prevent parallax from kicking in during pulldown by adding the following to the top of the animate function:

if (window.pageYOffset < 0) { return false; }

Just a thought ; )

Issue with npm

I’m getting an Uncaught Reference Error: Rellax is not defined error.

here’s how I’m calling it:

require('rellax');
let rellax = new Rellax('.rellax');

Link broken

The link on your site to your Github page is broken, just thought I would give you peeps a heads up.

translate3d creating a blank space

Might be using this wrong, but the last "rellax" div on the page creates a big blank space on the page as it translates upward. Any ideas?

Thanks for a good simple library!

Callback

For those who are looking for callback option!!
Fork: https://github.com/susonwaiba/rellax

Callback

<script>
  // Start Rellax
  var rellax = new Rellax('.rellax-blur-card', {
    callback: function(position) {
      // callback every position change
      console.log(position);
    }
  });
</script>

pause and resume methods

Maybe you could add pause and resume methods. This could already do the trick:

    self.resume = function () {
        pause = false;  
    };

    self.pause = function () {
        pause = true;
    };

Screen height on orientation change

Would it be worth setting screenY = window.innerHeight; again within the window resize event listener? I'm thinking, when an ipad is rotated, the screen height changes.
Thanks

z-index request

Hi your plugin is great but I think a data-z-index would make it better again.
What do you think ?

Allow to add elements after initialization

After library initialization we can't add new elements. It's a problem in some cases like images with lazy-loading.
A method to load other elements should exists.

First step : library initialization

var rellax = new Rellax('.rellax');

Second step : add (@todo)

rellax.load('.other_class');

Thanks.

Anchor tag forces incorrect positioning

Rellax is great, though I'm wondering if you have a solution for my issue:

I have anchor links on my site. Clicking an anchor jumps to the relevant section (obviously, expected behaviour). The issue is that the positioning of all the rellax elements stays where they are pre-scroll. Is there a way to update the position when an anchor tag is clicked?

Is it possible to use this for parallax images in between content?

Every other parallax library I've looked at has had to have special markup to separate the images that are supposed to be parallax in the background from the static images that scroll like normal, usually the content divs etc.

I like how simple the syntax of this library is, but all the examples seem to focus on a page of moving objects rather than the interspersed parallax amongst normal content. If I set the objects I went to be static to a speed of zero will that achieve the same effect?

Mobile performance

Hi

Thanks for making this available. Love the desktop experience. Very smooth. But the mobile experience is not performant and doesn't seem to implement parallax at all. Any tips to improve that? (iOS 10 > Latest Chrome + Safari)

Thanks

Relative anchoring

Love this handy little library! Thanks for creating it.

We've used skrollr in the past and it has an invaluable feature I wonder if you might consider borrowing. With skrollr, you can base your element's scroll position on the main window or against another element on the page using the 'data-anchor-target' attribute. Relative anchoring keeps the relationship between two items consistent between very short pages and very long pages, for example.

Curios to know if this is a use case you've ever experienced and whether it might be added to the library at some point?

No iOS Safari support

Looks like the plugin doesn't work with Safari on iOS (tried iOS 8,9 & 10) - works fine with OSX Safari.

Using Custom Scrollbar instead of native Scrollbar

Hi, is it possible to detect custom scrollbar or creating new option to bind to custom scrollbar rather than using native scrollbar. Maybe it can provide selector to some class or DOM rather than only binding it to window. Btw, nice to use this plugin. It is very easy to use.

Wrapper

Hi,

it's really nice script. I found a issue in some of my projects - template is based on absolute wrapper.

Ex.

<div class="Layout__wrapper-container">
    <div class="Layout__wrapper">
        [...]
    </div>
</div>

CSS

.Layout__wrapper-container
    position: absolute;
    width: 100%;
    height: 100%;

.Layout__wrapper
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;

Because of that all my scroll based scripts have to be added on .Layout__wrapper. It would be awesome if this script would have option to decide which wrapper use.

Edit: I closed because of that: #27

Request to implement delay on some elements

How feasible is it to implement a 'delay' method so it would be possible to keep some elements in place for specified amount of time before they get animated (follow the scroll)? Primary use is for the elements that are located "above the fold". Looking for a way to start parallax scroll with elements animated one by one.

iOS - iPhone

does this work for you on iOS (iPhone) - Safari?
thanks!

Better selector !!

Hi,

Thanks for this great script. Now scripts works fine with

var rellax = new Rellax( '.relax' );

But i think it will be much better, if you improve selector detection like this:

var rellax = new Rellax( '[data-rellax-speed]' );

Or add [data-rellax-speed] inside script, in this case even we do not need to call relax and it will detect all elements rellax-speed by default.

Regards

Moving in the right direction?

I am wondering if the behaviour changed on the direction that the parallax element is moving. I believe before the element used to move down as the user scrolled down, but now it seems to move up as the user scrolls down.

I have two 100vh sibling divs, the first div having the rellax being applied to the background. When I scroll down, a white gap appears because of the direction of the background moving up.

Object.freeze() ie11

IE11 fails with
IE Fail
which is argument is not an object in English.
Happens on line Object.freeze();

Are you sure guys there's no need to pass object to Object.freeze()?
At least for IE argument is mandatory.
Do you think everyone uses ES6?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.