Parallax scrolling jQuery plugin

Overview

paroller.js

npm
A lightweight jQuery plugin that enables parallax scrolling effect

  • You can use it on elements with background property or on any other element
  • While scrolling elements can move: vertical, horizontal
  • Manipulated through html data-* attributes or jQuery options
  • Mobile ready
  • Easy to use

DEMO: Demo, Example page, Example page

Install

Before closing </body> element include:

  1. jQuery
  2. jquery.paroller.js

npm

$ npm install paroller.js  

Yarn

$ yarn add paroller.js  

Bower

$ bower install paroller.js  

CDN

jsDelivr, unpkg, bundle.run

Use

//a) initialize paroller.js 
$('.my-paroller').paroller();  

//b) initialize paroller.js and set attributes 
$(".my-element").paroller({ factor: 0.5, factorXs: 0.2, factorSm: 0.3, type: 'foreground', direction: 'horizontal' });  
<!-- a) select element and set attributes --> 
<div class="my-paroller" 
    data-paroller-factor="0.4" 
    data-paroller-factor-xs="0.2" 
    data-paroller-factor-sm="0.3" 
    data-paroller-type="foreground" 
    data-paroller-direction="horizontal"
>

<!-- b) select element -->  
<div class="my-element"></div>  

npm and browserify

require('paroller.js');  

Options

data attributes

You can control parallax effect by data-paroller-* or jQuery values.

data-paroller-* jQuery value default value
data-paroller-factor factor number (+/-) 0
data-paroller-factor-xs factorXs number (+/-) 0
data-paroller-factor-sm factorSm number (+/-) 0
data-paroller-factor-md factorMd number (+/-) 0
data-paroller-factor-lg factorLg number (+/-) 0
data-paroller-type type background, foreground background
data-paroller-direction direction vertical, horizontal vertical
data-paroller-transition transition CSS transition transform 0.1s ease

data-paroller-factor

Sets speed and distance of element's parallax effect on scroll. Value can be positive (0.3) or negative (-0.3). Less means slower. Different sign (+/-) means different direction (up/down, left/right).

⚠️ Since factor is multiplier it must be set for paroller.js to have parallax effect.

data-paroller-factor-*

Sets paroller factor for selected breakpoint.

data-paroller-factor-* jQuery option window width breakpoint
Extra small data-paroller-factor-xs factorXs <576px
Small data-paroller-factor-sm factorSm <=768px
Medium data-paroller-factor-md factorMd <=1024px
Large data-paroller-factor-lg factorLg <=1200px
Extra Large data-paroller-factor-xl factorxl <=1920px

data-paroller-transition

Only effects elements with paroller.js type set to foreground!

JavaScript

// initialize paroller.js and set attributes for selected elements  
$(".paroller, [data-paroller-factor]").paroller({  
  factor: 0.2,            // multiplier for scrolling speed and offset, +- values for direction control  
  factorLg: 0.4,          // multiplier for scrolling speed and offset if window width is less than 1200px, +- values for direction control  
  type: 'foreground',     // background, foreground  
  direction: 'horizontal', // vertical, horizontal  
  transition: 'translate 0.1s ease' // CSS transition, added on elements where type:'foreground' 
});  
Set factor breakpoints
// initialize paroller.js and set attributes for selected elements  
$(".paroller, [data-paroller-factor]").paroller({  
    factor: 0.3,        // +/-, if no other breakpoint factor is set this value is selected  
    factorXs: 0.1,      // factorXs, factorSm, factorMd, factorLg, factorXl      
    factorSm: 0.2,      // factorXs, factorSm, factorMd, factorLg, factorXl      
    factorMd: 0.3,      // factorXs, factorSm, factorMd, factorLg, factorXl      
    factorLg: 0.4,      // factorXs, factorSm, factorMd, factorLg, factorXl
    factorXl: 0.5       // factorXs, factorSm, factorMd, factorLg, factorXl
    type: 'foreground',     // background, foreground  
    direction: 'horizontal',// vertical, horizontal 
    transition: 'translate 0.1s ease' // CSS transition, added on elements where type:'foreground' 
});  

License

MIT

Comments
  • Jump on scroll vertically

    Jump on scroll vertically

    Lovely plugin! I have a simple 2 full width containers with backgrounds, I set up the parallax vertically on the second container (which is below the first one.), the moment you start scrolling, the 2d container jumps down a distance before it starts smoothly parallax. is it a bug? thanks

    I am using the latest version 1.4.6.

    opened by oueryemchi 25
  • Content jumps down

    Content jumps down

    First of all, this is an easy to use and great plugin for achieving parallax effects. Kudos to you! I'm still having an issue that resembles issue #50. When scrolling, the content at the top of the page jumps down. I've updated the plugin with the latest js but the problem is still there.

    opened by timoanzalone 12
  • Destroy and re-initiate on window resize

    Destroy and re-initiate on window resize

    Great plugin, very easy to use however I am having an issue where the values end up being wrong when the window is re-sized. This is due to the size of containers and objects changing due to media query breakpoints. So I need to re-calculate the transforms on window resize. Is there a destroy/re-calc function?

    opened by functionandform 11
  • alter data attribute with media queries?

    alter data attribute with media queries?

    Can you suggest a way to have a different data-paroller-factor on smaller screens than on desktop? I am using paroller to add parallax to text, and on smaller screens this creates issues. I'd like a desktop data-paroller-factor of -0.35 but on mobile either 0 or closer to 0. Not sure how to do this. Thanks for any ideas you can suggest!

    enhancement 
    opened by jough74 8
  • `factor` overwrites the factor of other breakpoints

    `factor` overwrites the factor of other breakpoints

    When I apply paroller to an element and I'd like to have a default behavior/factor, I can't override that default with breakpoint-specific factors (e.g. factorMd, factorXs).

    Javascript:

    $("#annoncer-screen").paroller({ factor: 0.3, factorMd: 0, type: 'foreground', direction: 'vertical' });
    

    SCSS:

    #annoncer-screen {
        width: 116.667vw;
        overflow: visible;
        z-index: 5;
        position: relative;
        left:8.333vw;
        img {
            width: 100%;
            transform: rotate(10deg);
            box-shadow: 0.5rem 4rem 4rem -1rem rgba(45, 62, 80, 0.6), 1rem 1rem 2.5rem 0rem rgba(0, 0, 0, 0.7);
        }
    }
    @media (min-width: 1024px) {
        #annoncer-screen {
            position: absolute;
            width: 1000px;
            left: 8.333vw;
        }
    }
    

    The breakpoint-specific values seem to work, as long as I do not set the 'default' factor value. In the code example above, factorMd seems to be overwritten or ignored when scrolling. This seems to happen regardless of:

    • Factor value (I tried 0, a positive value and a negative value)
    • Positioning of the Paroller'd element (I've tried setting both to position: absolute, as well as the styling above)

    Is this intended behavior? If so, how could I have a specific value for factorMd, which having a 'default' factor value for anything above that breakpoint?

    opened by JeroenRoodIHS 5
  • Elements shift down only when at top of page

    Elements shift down only when at top of page

    If I reload / visit a page and I'm at the very top, the elements that have Paroller applied to them are positioned where they're intended to be, however, when I start to scroll, they jump down from where they're intended to be, but the parallax effect works fine.

    However, if I scroll down the page just a little bit from the top, and reload the page, the elements are positioned lower than where they're intended to be. As I start to scroll, they don't jump down, they just work as the parallax effect.

    Any idea what's going on? Maybe Paroller isn't being initiated at the load of a new page?

    Thanks in advance for your help!

    opened by abaney 4
  • Hero section problem

    Hero section problem

    Great plugin, however, I have a little issue and all my tries to solve it went with the wind.

    I have a fullscreen hero section with a line of text centered vertically and horizontally, and I want the text to have vertical parallax animation on scroll.

    The problem is when I apply paroller on the text (using data attributes) it's not centered anymore when page scroll = 0. It has a little bit of initial translate transform up or down depending on the direction I set. I can understand this is useful when applying paroller on an element in the middle of the page, but when it applied to an element in the first section (like hero section in my case) this initial transform will break the layout. The text element should be in its original place, then it moves slowly on scroll.

    I tried to play with the calculations in the code but had no luck. If someone can give an advice I will appreciate it.

    Regards

    enhancement 
    opened by premitheme 4
  • NPM Support & mobile bug

    NPM Support & mobile bug

    Hey, first thanks for the awesome plugin. It would be nice if the plugin supports npm. The other thing is, that the horizontal parallax isn't working on mobile. Cheers.

    opened by ceehaupt 4
  • Elements with background scroll snap once after refresh

    Elements with background scroll snap once after refresh

    Hi, I'm having some trouble with the plugin. It does work, I had no problem initiating it etc., however, when I scroll down to a paroller-initiated element (I only use vertically scrolled backgrounds in my project btw) and then refresh the page, the background-position value is wrong at first. It does change to a correct one, right after I scroll the page either up or down, but it happens in a snap and it just looks terrible :(

    It's really weird, because I even copied the example from the plugin website and imported the same jquery and plugin versions to check it, and it still snapped after refresh.

    Here's a screenshot of background-position before and after scrolling the page down about 80px after refresh: image

    opened by urban07 3
  • Using Paroller on elements at the top of the page

    Using Paroller on elements at the top of the page

    Hi!

    I am hoping to have an element positioned at the top of the page (a Hero Banner) and I want to implement paroller so that its' content parallaxes.

    At the moment it seems on page-load paroller kicks in and applies the transform despite not started scrolling yet. For example transform: translateY(-84px);, which causes an unwanted gap.

    How is it possible to have transform initiate at 0 or null so that it is only applied when the user starts scrolling.

    Thank you and great job

    opened by elliott-impression 3
  • Default Setup not working?

    Default Setup not working?

    Hey,

    I have set up my div like this:

    <div class="col-sm-12" id="some-div" data-paroller-factor="0.3" data-paroller-type="foreground" data-paroller-direction="horizontal">
            <div class="row">
                <div class="div-container col-sm-6">
                    <img src="<?php echo plugins_url('module/images/'). 'placeholder.jpeg'; ?>" class="img-responsive" />
                    <p>TAGLINE</p>
                </div>
            </div>
    
            <div class="row">
                <div class="div-container col-sm-6 col-sm-offset-6">
                    <p>ANOTHER TAGLINE</p>
                    <img src="<?php echo plugins_url('module/images/'). 'placeholder.jpeg'; ?>" class="img-resposnive" />
                </div>
            </div>
    
            <div class="row">
                <div class="div-container col-sm-6">
                    <h3>YET ANOTHER TAGLINE</h3>
                    <img src="<?php echo plugins_url('module/images/'). 'placeholder.jpeg'; ?>" class="img-responsive" />
                </div>
            </div>
        </div>
    

    And my jQuery:

        //parallax scroll
        $('#some-div').paroller();
    
        $('.div-container').paroller({
            factor: 0.5,
            factorXs: 0.2,
            type: 'foreground',
            direction: 'horizontal'
        })
    

    my console outputs:

    TypeError: $(...).paroller is not a function

    What am I doing wrong?

    I've checked my element and can see the