Giter VIP home page Giter VIP logo

react-plx's Introduction

Plx - React Parallax component

npm version npm downloads

React component, for creating on scroll effects aka. parallax. Lightweight, yet powerful.

Version 2 brings even more performance improvements and TypeScript support.

  • v2.0.0 breaking changes

    • px units are not assumed and need to be provided manually
    • tagName prop was removed it was returned in v2.1.0

Changelog

Demo

Check the live demo. You can find source for the demo here.

Plx example, exploding elements

I would really like to see what you people have built using Plx and create a showcase section. So please open an issue titled Showcase: <your awesome stuff> so it can be featured. Cheers!

Quick start

Get it from npm

$ npm install --save react-plx

Import and use it in your React app.

import React, { Component } from "react";
import Plx from "react-plx";

// An array of parallax effects to be applied - see below for detail
const parallaxData = [
  {
    start: 0,
    end: 500,
    properties: [
      {
        startValue: 1,
        endValue: 2,
        property: "scale",
      },
    ],
  },
];

class Example extends Component {
  render() {
    return (
      <Plx className="MyAwesomeParallax" parallaxData={parallaxData}>
        /* Your content */
      </Plx>
    );
  }
}

Table of contents

What is this?

This is React component which makes creating on scroll effects (aka parallax) easy. If you are not sure what it does, demo should help.

It is lightweight, and beside react, react-dom and prop-types has no dependencies, now it has small bezier-easing package. As listening to scroll event is not performant, this component uses different approach. Interval is set (every 16ms to get 60fps) to check if scroll position is changed, and if it is, it broadcasts custom event. All of the Plx components are sharing the scroll manager singleton. Interval is set when the first component is created, and cleared when last one is unmounted. Interval time can be changed through the props, but it is shared across the components.

Elements outside of viewport are not animated. This is done by using getBoundingClientRect, but there is a known bug in iOS with getBoundingClientRect and position fixed. If you get into the same problems, you can force rendering by passing animateWhenNotInViewport={ true }.

Still you need to avoid common "don't dos" when making a parallax page:

  • Avoid background-size: cover
  • Don’t animate massive images or dramatically resize them
  • Avoid animating 100 things at once
  • Only use properties that are cheap for browsers to animate - opacity and transform (translate, rotate, skew, scale)

Read this great article to find out more (that is where I got my initial inspiration).

Of course, you can break any of these rules, but test for performance to see if it works for you.

Component is written as ES module, so it will work with webpack and other module bundlers (which is standard for React apps anyway). Tested with react-create-app and my boilerplate, Marvin.

Read more about how it works in this blog post.

Props

  • className string

    CSS class name (it will be applied along with Plx class name).

  • style object

    CSS style object, please note that properties used in parallax will be overridden by component.

  • animateWhenNotInViewport bool, default false

    If set to true element will be animated even when it is not in the viewport. This is helpful with fixed elements in iOS due to know bug with getBoundingClientRect in iOS.

  • disabled boolean

    When true disabled animation completely.

  • freeze bool, default false

    When true animation will be stopped at current state when condition is met.

  • parallaxData array of items (item structure described beneath), required

    Main data, describes parallax segments.

  • onPlxStart function

    If set, the Plx component will call this function each time the animation state changes to active. (refer to animation state CSS classes)

  • onPlxEnd function

    If set, the Plx component will call this function each time the animation state changes from active to another state. (refer to animation state CSS classes)

  • tagName string, default "div"

    HTML or SVG element tag name to be used.

Any other props will be passed to the component (for example this is useful for aria-* props).

parallaxData

  • start number, string, HTMLElement, required

    Scroll position where parallax effect should start. Can one of the following:

    • Number - value in pixels
    • String
      • Value in px, vh or % (50px, 50%, 25vh). Percentage is calculated out of max page scroll.
      • CSS Selector (.my-element, #some-id) to be used with document.querySelector.
      • "self" component's element will be used
    • HTMLElement, given element will be used.

    For element, selector and "self" animation will start when that element enters the viewport. You can use startOffset prop to offset start position.

    Example:

    start: 100; // starts when scroll hits 100px
    start: "self"; // starts when plx's element enters the viewport
    start: ".start-element"; // starts when .start-element enters the viewport

    PLEASE NOTE that parallaxData should be sorted by start value!

  • end number, string, HTMLElement

    Scroll position where parallax effect should end. It has higher priority than duration. Can one of the following:

    • Number - value in pixels
    • String
      • Value in px, vh or % (50px, 50%, 25vh). Percentage is calculated out of max page scroll.
      • CSS Selector (.my-element, #some-id) to be used with document.querySelector.
      • "self" component's element will be used
    • HTMLElement, given element will be used.

    For element, selector and "self" animation will end when that element enters the viewport. You can use endOffset prop to offset end position.

    Example:

    end: 300; // ends when scroll hits 300px
    end: "self"; // ends when plx's element enters the viewport
    end: ".end-element"; // ends when .end-element enters the viewport
  • duration number, string, HTMLElement

    How long should effect last (it will finish when scroll position equals start + duration). It will be used if end is not defined. Can one of the following:

    • Number - value in pixels
    • String
      • Value in px, vh or % (50px, 50%, 25vh). Percentage is calculated out of max page scroll.
      • CSS Selector (.my-element, #some-id) to be used with document.querySelector.
    • HTMLElement, given element will be used.

    For element and selector, element's height will be used as duration. Any other string will be considered CSS selector and it will be used with document.querySelector.

    Example:

    duration: 300; // animation will last for 300px
    duration: ".duration-element"; // animation will last for .duration-element's height
  • startOffset number, string

    Start offset, can be a number or string value in px, vh or % (50px, 50%, 25vh).

  • endOffset number, string

    End offset, can be a number or string value in px, vh or % (50px, 50%, 25vh).

  • easing string, function or array, default: 'linear'

    Easing function, you can pass the name (string) to choose one of the built-in functions. Built-in easing functions are:

    • ease
    • easeIn
    • easeOut
    • easeInOut
    • easeInSine
    • easeOutSine
    • easeInOutSine
    • easeInQuad
    • easeOutQuad
    • easeInOutQuad
    • easeInCubic
    • easeOutCubic
    • easeInOutCubic
    • easeInQuart
    • easeOutQuart
    • easeInOutQuart
    • easeInQuint
    • easeOutQuint
    • easeInOutQuint
    • easeInExpo
    • easeOutExpo
    • easeInOutExpo
    • easeInCirc
    • easeOutCirc
    • easeInOutCirc

    Cubic beziers are supported, pass an array to it with four points of your custom bezier (you can copy CSS beziers).

    easing: [0.25, 0.1, 0.53, 3];

    You can even pass custom function which accepts one argument, which will be number from 0 to 1.

    // Define your custom easing
    const myCustomEasing = (x) => {
      return x * x;
    };
    
    ...
    
    // and then pass it to Plx
    easing: myCustomEasing
  • name string (without spaces)

    Name used in animation state CSS classes

  • properties array of items (item structure described beneath), required

    List of properties to be animated

properties

  • property string, required

    CSS property to be animated, works only on properties which accept numerical values (e.g. opacity, height...). For transform use function names instead (e.g. translateX, scale, rotate...). Same goes for filters.

    For properties that use pixels (height, width, margin...), please be sure to provide unit: "px" prop.

    Supported transform functions are:

    • translateX
    • translateY
    • translateZ
    • skew
    • skewX
    • skewY
    • skewZ
    • rotate
    • rotateX
    • rotateY
    • rotateZ
    • scale
    • scaleX
    • scaleY
    • scaleZ

    Supported colors are:

    • backgroundColor
    • borderBottomColor
    • borderColor
    • borderLeftColor
    • borderRightColor
    • borderTopColor
    • color
    • fill
    • stroke

    Supported CSS filters are:

    • blur
    • brightness
    • contrast
    • grayscale
    • hueRotate
    • invert
    • opacityFilter (as it shares the same name as CSS opacity)
    • saturate
    • sepia

    To keep you parallax effects performant, I strongly advice not to use anything but opacity and transforms. Some filters should be cheap as well, with blur being the most expensive out of supported filters.

  • startValue number (or string for color), required

    Start value for the effect. Property will have this value when scroll position equals parallaxData.start. For colors supported formats are: #123, #001122, rgb(0,0,255) and rgba(0,0,255,0.5).

  • endValue number (or string for color), required

    End value for the effect. Property will have this value when scroll position equals parallaxData.end. For colors supported formats are: #123, #001122, rgb(0,0,255) and rgba(0,0,255,0.5).

    Between parallaxData.start and parallaxData.end value will transition relative to scroll position.

  • unit string

    CSS unit (e.g. %, rem, em...) to be applied to property value. For transforms and filters library is using pixels and degrees by default. For everything else please provide appropriate units (i.e. "px" for "height").

Example of props

These are the exact props used in this example.

const exampleParallaxData = [
  {
    start: 0,
    end: 300,
    properties: [
      {
        startValue: 0,
        endValue: 90,
        property: "rotate",
      },
      {
        startValue: 1,
        endValue: 1.5,
        property: "scale",
      },
      {
        startValue: 1,
        endValue: 0.75,
        property: "opacity",
      },
    ],
  },
  {
    start: 350,
    duration: 300,
    properties: [
      {
        startValue: "#3cb99c",
        endValue: "rgba(50,50,200,0.8)",
        property: "backgroundColor",
      },
      {
        startValue: 0,
        endValue: 100,
        property: "translateY",
      },
      {
        startValue: 0.75,
        endValue: 1,
        property: "opacity",
      },
    ],
  },
  {
    start: 700,
    duration: 1000,
    properties: [
      {
        startValue: 100,
        endValue: 0,
        property: "translateY",
      },
      {
        startValue: 1.5,
        endValue: 2,
        property: "scale",
      },
      {
        startValue: 90,
        endValue: 0,
        property: "rotate",
      },
      // Blur is not performant
      // Used just as an example for CSS filters
      {
        startValue: 0,
        endValue: 20,
        property: "blur",
      },
    ],
  },
];

Animation state CSS classes

Component will also apply CSS classes that match current animation state. Classes are:

  • Plx--above scroll position is above first start position (animation isn't started yet)

  • Plx--below scroll position is below last end position (animation is finished)

  • Plx--active scroll position is below first start and last end position (animation is in progress, including between states)

  • Plx--in Plx--in-{n} scroll position is in n-th segment (Plx--in-0, Plx--in-1...). If name prop is passed (see above) it will be used instead of index (Plx--in-superDuperName).

  • Plx--between Plx--between-{a}-and-{b} scroll position is between segments a and b (Plx--between-0-and-1, Plx--between-1-and-2...) If name prop is passed (see above) it will be used instead of index (Plx--between-superDuperName-and-anotherName).

active class is applied along with both in and between classes.

Browser support

All modern browsers.

Since version 2, I'm not supporting nor testing it in Internet Explorer. Library will probably work in IE10+ and even IE9 should work if you provide a polyfill for requestAnimationFrame.

License

Released under MIT License.

react-plx's People

Contributors

adam187 avatar allesklarbeidir avatar dependabot[bot] avatar ianboyte avatar idfunctor avatar markomarkom avatar novojin avatar oleast avatar stanko avatar stefl avatar whotakesmyname 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

react-plx's Issues

Possibility to animate backdropFilter

I have a feature request:

What about being able to animate the backdropFilter property as well?

I think we could easily add the following filters for backdropFilter within react-plx pretty easily, since they only use linear values:

blur();
brightness();
contrast();
grayscale();
hue-rotate();
invert();
opacity();
sepia();
saturate();

I would not add drop-shadow since we would have to accept four arguments here:
drop-shadow(4px 4px 10px blue);.

Furthermore I can not think of a way to animate the svg filters via backdrop-filter: url(commonfilters.svg#filter);

I am gladly willing to contribute and open a PR if you approve the feature :)

Run independent animation after scroll reaches an element

I am trying to figure out how to trigger the animation using "self" as start, but I need it to start even if my scroll does not move anymore after reaching it, animation must run by it self when I reach the element. Is that possible?

EDIT: I was reading other issues and saw the author indicating for that case I should use react-reveal, so I am closing this issue.

VERY choppy animation with image parallax -- am I doing something wrong?

So.. I was trying to use plx for a fairly "traditional" parallax effect: a section with a background image that scrolls away slower than the rest of the page.

What I did was create a container with position: relative and two "layers" inside, with position: absolute and top/left/right/bottom set to zero, to fill the entire container.
Plx components are then used to translate the content of the layers to create the parallax effect.

Unfortunately something doesn't seem to be working properly, resulting in a very noticeable delay in the animation (on Chrome) / very bad, choppy animation (on Firefox).

Am I doing something wrong? Is there a "cleaner" way to implement such an effect using Plx?

Revisit start/end/duration props

  • Introduce end which can be used instead of duration.
  • Find more intuitive (sane) way of defining these props.
  • Check if we need all of these document height properties, and move it to a separate method
  • Save references to dom elements.
  • Check if we need dual pass through segments (I had some issues with it, but can't remember what it was 😕). loop 1 - loop 2
  • Update documentation accordingly.

Feel free to break these into multiple issues.

TypeScript types

I have to add types, for now they are available here:

interface PropertiesItemType {
  startValue: string | number;
  endValue: string | number;
  property: string;
  unit?: string;
}

interface ParallaxDataType {
  start: string | number | SafeHTMLElement;
  startOffset?: string | number;
  duration?: string | number | SafeHTMLElement;
  end?: string | number | SafeHTMLElement;
  endOffset?: string | number;
  properties: PropertiesItemType[];
  easing?: string | array | func;
  name?: string;
}

interface IPlxPros {
  animateWhenNotInViewport?: boolean
  children?: any;
  className?: string;
  disabled?: boolean;
  freeze?: boolean;
  parallaxData: ParallaxDataType[];
  style?: string | number | object;
  tagName?: string;
  onPlxStart?: PropTypes.func;
  onPlxEnd?: PropTypes.func;
}

declare module 'react-plx' {
  declare class Plx extends React.Component<IPlxPros> {
    constructor(props: IPlxPros)
  }
  export = Plx;
}

Getting `getBoundingClientRect` errors

Hi @Stanko, So I was giving react-plx a shot in my project and ran into the following errors in the console. They accumulated with the scroll.

Plx.js:378 Uncaught TypeError: Cannot read property 'getBoundingClientRect' of undefined
    at Plx.update (Plx.js:378)
    at Plx.handleScrollChange (Plx.js:360)
    at ScrollManager.handleInterval (scroll-manager.js:85)

Context: My usecase is that I have an full viewport image on the homepage that I am trying to have another full viewport container scoll on top of. So my setup looks like this:

<Plx parallaxData = {[
  {
	start:		100,
	duration:	"height",
	properties: [
		{
			startValue: 0,
			endValue: 	100,
			property: 	"height",
		},
	 ],
	},
	]}
> 
    <FullViewport> {/* <-----  Static Content */}
      <BackgroundImage />
      </FullViewport>
 </Plx>
 <FullViewport> {/* <---- Content that should be over the Static Content */}
   <OverlayContent />
</FullViewport>
<FullViewport>
  <MoreThings />
</FullViewport>

Another usage question was in my case, am I right in understanding that height is the property to animate? Or would you set it up differently like maybe on the OverlayContent component (or its parent)?

Thank you!

how to trigger function when plx starts / ends?

i would like to update a property of a component when the plx starts... but im not sure if that is possible with this library.

thoughts?

would be neat to have inside parallaxData a function onPlxStart or onPlxEnd or just onPlx that passes information that i can use to update react components?

Showcase: <https://simplx-web.herokuapp.com>

Hi Stanko ! We are a group of three junior web developer who has just about to finish our 9 weeks coding bootcamp. We have been learning react for two weeks and we really liked and enjoyed your React Plx package as the code is clean and easy to work with. We decided to make a website that showcases all your parallax effects and people willl be able to export code snippet based on the effects they have chosen. If you have time we would love you to take a look and give us some feedback . Thank you once again for making this awesome package!

best regards,
Min

email : [email protected]

Scrolling On IE Edge browser jumping and moving Plx divs

Nice plugging I applied it to my project and it works well on chrome and FF however when scrolling on IE browser it moving with jumping behavior. Can you please help me to sort this out.

I also included below and tried when scrolling on IE still moving with unexpected jumping behavior.

import 'core-js/es6/map';
import 'core-js/es6/set';

import smoothscroll from 'smoothscroll-polyfill';
smoothscroll.polyfill();

====================
below are my code I want to control the div moving speed with the user scrolling.

{
start: Number(100),
end: Number(500),
properties: [
{
startValue: 0,
endValue: 250,
property: 'translateY'
}
]
}

All parallax triggers tied to single element

Hi, really appreciate this library.

I'm trying to use it in a project I have, but am encountering this weird this weirdness where the parallax events are all triggered when one element is in view and otherwise do nothing.

Basically I have a component Project and it looks something like this:

<div>
    <Plx>
        <img/>
    </Plx>
    <Plx>
        <p>description</p>
    </Plx>
</div>

Now elsewhere I have my App which is like

<div>
   <Project />
   <Project />
</div

And the first Project's parallax effect only starts when the second one starts i.e. they are in sync. Any advice why this might be?

Thanks.

Support scrolling on non-window element

Thanks for making react-plx. I've ran into a semi-serious feature that doesn't yet exist in that all scroll events are expected to come from the window. This makes it impossible to do something like body { overflow: hidden; } and have some child element actually be the one scrolling.

The feature request would be for plx to accept a scroll target, which means implementing it in both plx and scroll manager.

Negative scrolling in Safari

How to disable the negative scrolling in Safari?
Initially, the animation works ahead of time.

bug mov

const exampleParallaxData = [
  {
    start: 0,
    end: 300,
    properties: [
      {
        startValue: -500,
        endValue: 100,
        property: "translateX"
      }
    ]
  }
]

const Masters = () => (
  <div style={{ height: 4000 }}>
    <Plx parallaxData={exampleParallaxData}
        style={{
          position: 'fixed',
          bottom: '0vh'
        }}
      >
        <Image source={One} style={{width: 600, height: 600 }} />
    </Plx>
  </div>
)

Plx does not render startValue and endValue values that are 'string' based units

Hello Stanko,

My project requires string based transforms for the CSS properties although it appears the logic on lines 327 and 333 are preventing this use case with the following parallaxData array.

const parallaxData = [
    {
        start: 0,
        duration: 500,
        properties: [
            {
                startValue: 0,
                endValue: '50%',
                property: 'translateY'
            }
        ]
    }
];  

Expected:
Plx should render startValue and endValue values that are 'string' based units (50px, 50%, 25vh).

Actual results:
Plx does not render startValue and endValue values that are 'string' based units (50px, 50%, 25vh).

Plx, ERROR: endValue is not a number (type: "string", value: "100%")

Thanks in advance,
Alden

React 15.6 - Warning on setting css properties

React Version: 15.6.0
React Version: 16 (fails completely)

Message: Warning: a 'div' tag (owner: 'unknown') was passed a numeric string value for CSS property 'background-position-x' (value: '-1.86') which will be treated as a unitless number in a future version of React.

<Plx
      className="section-2"
      style={{
        zIndex: 10,
        height: "100vh",
      }}
      parallaxData={[{
        start: ".start-section-2",
        duration: 700,
        name: "first",
        properties: [
          {
            startValue: 0,
            endValue: -50,
            property: "backgroundPositionX",
          }, {
            startValue: 0,
            endValue: -20,
            property: "backgroundPositionY",
          }
        ],
      }]}>

Showcase: <antoniocosentino.com>

Hello @Stanko, first of all thanks for creating such a nice component!
I finally published the new version of my website antoniocosentino.com and I'm using react-plx in the following pages:

In the above-mentioned article I'm also briefly talking about my experience with this component compared to other ones that I tried previously.

Thanks again for the great work :)
Antonio

TypeScript types missing

Since I couldn't find @types/react-plx, how do I import this to my react project? Any help? thanks!

Visibility: hidden until react-plx load

I have an isomorphic application that renders a header with an image + text. I'm using react-plx to provide a parallax effect where the image and text scroll at different rates. When my server renders the HTML, the line below from react-plx makes the image + text area not visible until after JS has loaded:

visibility: showElement ? null : 'hidden',

If I disable Javascript on my browser (so that I view the server side rendered HTML only), I would expect the image + text to load and scroll as normal with the page. Instead, I don't see any image or text and it just looks weird. I see the same thing on your live demo site: without Javascript turned on in the browser, none of the content loads below the link to Github.

Do you think there's a way to refactor the showElement logic so that the content is rendered on page load and then changed when the client takes over? Or does that cause the page to jump if scrolled?

Element hidden on load when using with gatsby

When using gatsby, a Plx element remains hidden (display: 'hidden') and only shows, when you start scrolling. This happens about 50% of the time and seems to be a race condition.

I believe this is an issue with gatsby, because it doesn't support using_window_ inside render(). Using _animateWhenNotInViewport _ works as a workaround. I can't give you much insight though as I'm still new to the ecosystem.

Comparison with react-scroll-parallax

Hi @Stanko, Thank you for putting out this library, it looks really promising. I am curious, as the author, if you have any thoughts comparing react-plx with react-scroll-parallax (the only other library which looked promising)?

Any points of comparison/pros/cons from your point of view would be super helpful in deciding between the two.

Percentage based start trigger?

In many cases, for example, making columns of a row appear one by one(using opacity), staggered, works great on let's say a 1920x1080 device. But the same configuration makes the boxes appear too soon on a 1388x768 device. Assuming that this row of staggered columns is at the end of a page, on an iPad, due to the huge height, the element id provided would never reach the page top, and hence the columns would never appear all.
On the other hand instead of using ids, if one uses a number, that too is in pixels and would cause really inconsistent animations.
If you could just provide me on some insight on the best way to solve this problem then I wouldn't mind spending my time coding the enhancements and contributing to the library, thanks.

Negative scroll positions

Problem:
On macOS you can scroll a little further than the actual size of the html document resulting in a rubber effect. This is only implemented in Chrome and Safari, but only produces negative pageYOffset values on Safari, resulting in glitching of the parallactic objects when pageYOffset goes below 0.

Possible Solution:
Without having looked through the code I assume the position tracking is done by pageYOffset lookups. Would it be possible to cap the scroll position at 0, which would save me a lot of workarounds? Or might this feature be useful in some cases?

Ability to use viewport units

Hey there 👋
This component looks good, I have only one suggestion.
It would be very useful for responsive layouts where scroll height changes and it's not reliable, if we could use viewport units (vh, vw) for start, duration and end.
Apple is doing something similar
screen shot 2017-09-18 at 00 07 30

I have a page with the same component - the scroll position is always related to the first child

I have a component that I re-use in different places on the page. Inside this component, I'm using react-plx to change an element inside my component. The scroll position seems to be working only on the first time I'm using my component.
This means the parallaxData are not working properly, they work for the first child, but scroll position is always 100% for the next childs..

Hope it make sense

HTMLElement is not defined

Getting this error when trying to use react-plx in a next.js project.

HTMLElement is not defined
ReferenceError: HTMLElement is not defined
    at Object.<anonymous> (/Users/levonarakelyan/projects/mojilytics/landmoji/node_modules/react-plx/lib/Plx.js:757:128)
    at Module._compile (module.js:570:32)
    at Module._compile (/Users/levonarakelyan/projects/mojilytics/landmoji/node_modules/source-map-support/source-map-support.js:492:25)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/levonarakelyan/projects/mojilytics/landmoji/node_modules/react-plx/lib/index.js:8:12)

Probably just because there's no HTMLElement when it's trying to render it on the server-side.

Thanks a lot @Stanko for a great lib!

Add Boolean `disabled` prop

Hello @Stanko !
is it possible to add Boolean disabled prop to have a possibility switch component off and do not
update styles during scrolling. it might be useful in case when animation should be disabled for mobile devises or some screen sizes.

Set `end:` as pixel-difference to `start` ?

Would be awesome if there would be a way to set the "end" parameter depending on the start-parameter.

Example:

      {
        "start":"self",
        "end":  <here>,  // self + px entered here
        "properties":[
          {
            "startValue":0,
            "endValue":300,
            "property":"translateY"
          }
        ]
      }

Means if "self" is on "1500px" and you set "end:" "+250px" this should result in setting end to 1750px.
Is there still a way to archive this?

react-native-web

Your library is something I've been looking for a very long time, but unfortunately I do not work with the library React Native Web

Сan you help solve this problem?
After the component AppRegistry is connected, the scroll disappears

import { AppRegistry } from 'react-native'
AppRegistry.registerComponent("MyApp", () => AppComponent)

Allow animation only trigger once?

Thanks for making this great library, really like the parallaxData option, it's so smart and convenient.

I'm now facing a request to let the parallax effect only runs on first time the element appears, and I find it's not easy with current exposed APIs. Mostly because of there is no easy way to know when does the element firstly fully displayed / visible (my idea is: setting freeze to true when element fully display, either when landing or after scrolling). I understand this might not be included in the design of this library, but any advice will be appreciated.

Maybe could consider add this feature?

Showcase: Ekaya Store

A lot of subtle transforms made easy and without depending unnecessarily on TweenMax as I'm used to; thanks to react-plx!
Ekaya

Working with Isomorphic Apps

Any thoughts on this...

ReferenceError: window is not defined
    at Object.<anonymous> (/Users/me/template/node_modules/react-plx/lib/scroll-manager.js:17:1)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/me/template/node_modules/react-plx/lib/Plx.js:25:22)
    at Module._compile (module.js:573:30)

State update on an unmounted component

Hello!

I keep getting this warning when I navigate to another page. I tried using freeze on componentWillUnmount but it didn't really help (example below). Version 1.3.15 on React 16.12.0 with Gatsby.

Warning:

index.js:2177 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
    in Plx (at Hero.js:287)
    in div (at Hero.js:286)
    in div (at Holder.js:10)
    in Holder (at Hero.js:285)
    in div (at Hero.js:284)
    in Hero (at services.js:205)
    in Layout (at services.js:203)
    in Services (at Context.js:15)
    in WrapperComponent (created by HotExportedWrapperComponent)
    in AppContainer (created by HotExportedWrapperComponent)
    in HotExportedWrapperComponent (created by PageRenderer)
    in div (at TransitionRenderer.js:49)
    in TransitionRenderer (at TransitionHandler.js:124)
    in Transition (at delayTransitionRender.js:30)
    in DelayedTransitionWrapper (at TransitionHandler.js:46)

Example:

const plxSubtitle = [
  {
    start: 0,
    end: "10vh",
    easing: "ease",
    properties: [
      {
        startValue: 0,
        endValue: 5,
        unit: "vh",
        property: "translateY",
      },
    ],
  },
  {
    start: "10vh",
    end: "30vh",
    easing: "ease",
    properties: [
      {
        startValue: 5,
        endValue: -10,
        unit: "vh",
        property: "translateY",
      },
    ],
  },
]

const plxTitle = [
  {
    start: "25vh",
    end: "60vh",
    easing: "ease",
    properties: [
      {
        startValue: 0,
        endValue: -10,
        unit: "vh",
        property: "translateY",
      },
    ],
  },
]

export const Hero = props => {
  const [freeze, setFreeze] = useState(true)

  useEffect(() => {
    setFreeze(false)

    return () => {
      setFreeze(true)
    }
  }, [])

  return (
    <Holder>
      <Plx
        parallaxData={plxSubtitle}
        freeze={freeze}
        className={styles.subtitlePlx}
      >
        <h4 className={styles.subtitle}>{props.subtitle}</h4>
      </Plx>
      <Plx parallaxData={plxTitle} freeze={freeze} className={styles.titlePlx}>
        <h1 className={styles.title}>{props.title}</h1>
      </Plx>
    </Holder>
  )
}

support clip-path?

hi, love this! it's very easy to use and the example is great. any thoughts or plans on supporting clip-path as one of the properties? i know it can be interpolated - i did a vanilla JS example with it a few years ago.

Fading in paragraphs similar to Medium article

Hi @Stanko, I had a quick usage question with the library that I was hoping you could help advice: Similar to the demo in the Medium article, I was looking to fade in text on scroll and then after it reaches at half the viewport, fade it out again.

So, now if I am doing it for a few paragraphs of text, am I correct in understanding that I'd need to put each paragraph inside a <Plx /> component, each with parallaxData arrays with two objects each of start (going from 0 opacity to 1 till 50% of the viewport) and end (and going from 1 to 0 for the next 50% of the viewport)? If yes, would you recommend any different but more performany way of achieving the same result?

Thank you!

Start + end 'self' values

Hi!

Cool project and I'm enjoying the API for this, seems to be the most logical out of the React parallax libraries I've tried out.

My issues is around using 'self' as the value around start/end. Took me a little bit to realise that this wasn't working as these both are triggered when the element enters the viewport, causing no value to be read and obviously there is no difference and therefore no duration. This is in the docs to be fair!

However, I think to create something truly reusable and dynamic, when there's no friendly static value to be used, the end value really needs to be when the element exits the viewport. This way you could have something that is parallaxed but is in its origin position when it is in the center of the viewport. Currently, I can't think of a way to factor in the height of the element and combine that with the built in offset props; the end value is always going to be something arbitrary as I don't know exactly where an element will be on the page to pass an accurate end value.

On IPhone when zooming page crash.

HI @Stanko Stanko Tadić

Thanks for Nice powerful and wonderful tool. We can do lot of parallax related animation easily.

I faced issue on iphone(ios) when zooming my page is crashing.

I have position fixed few divs and when scrolling I am doing zooming and set opacity to zero to visible other divs with the user scroll.

It works fine with desktop and android but normal scrolling works fine in iphone too. but when user zooming on iphone page crashing.
Do you have any idea?

Thank you very much.
:)

I

Explain how the sticky text works?

I can't seem to get that effect to work. To get something to stick I have to add a step where it is animating translateY in a positive direction, essentially fighting against the natural scroll, and because it is animating it's a bit wiggly. I'd love to get it to come in and stick and stay stable.

strokeColor seems to not work

Dear Stanko,

first of all, thank you very much for this amazing package! I was using it a lot in the past couple of weeks, it gives a really easy and intuitiv way to parallax effects!

Today I was trying to fill the path of a .svg file, but I can't get it to work. I noticed, that when the class changed to active (class="Plx Plx--active) no style is being applied.

I assume this behaviour is not intended?

Thank you very much for your help.
Malte

Interval issue when using in mobile

Hi @Stanko ,

I am trying to integrate this package in my app, but the performance is super slow, and sometimes the scroll event triggered after 1-2 seconds!

I start to debug it, and I think that in Android/iOS mobile browsers, the setTimeout and setInterval are disabled during scroll, and not triggered, and it takes about 1 second to the scroll manager to start and fire events...

Related:

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.