Code Monkey home page Code Monkey logo

react-springy-parallax's Introduction

*** This project has been merged into react-spring: https://github.com/drcmda/react-spring

*** Changes and bugfixes will go there instead.

--

A springy, composable parallax-scroller for React.

npm install react-springy-parallax --save

Demo: http://react-springy-parallax.surge.sh

Simple example: http://react-springy-parallax-simple.surge.sh

Example source: https://github.com/drcmda/react-springy-parallax/blob/master/example/index.js

More complex example: https://github.com/drcmda/awv3node-homepage (the one in the thumbnail)

intro

How to use

import Parallax from 'react-springy-parallax'

// Pages determines the total height of the inner content container
// Each page takes 100% height of the visible outer container by default
<Parallax ref='parallax' pages={3}>

    // Add as many layers as you like
    <Parallax.Layer
        // Page offset, or where the layer will be at when scrolled to
        // 0 means start, 1 second page, 1.5 second and half, and so on ...
        offset={0}
 ย  ย  ย  ย // Parallax factor, allows for positive and negative values
        // Shifts the layer up or down in accordance to its offset
        speed={0.5}>

        <span>Layers can contain anything</span>

    </Parallax.Layer>

</Parallax>

Can the effect be configured or muted?

Yes, you can use anything the Animated library offers: http://browniefed.com/react-native-animation-book

import Animated from 'animated/lib/targets/react-dom'
import Easing from 'animated/lib/Easing'

<Parallax
    effect={(animation, toValue) =>
        Animated.timing(animation, { toValue, duration: 200, easing: Easing.elastic(2) })}
    ... >

Or a zero timer for a tame, old-school parallax:

effect={(animation, toValue) =>
    Animated.timing(animation, { toValue, duration: 0 })}

Is it possible disable the scroll bar for custom page navigation?

Yes. In this mode it will also make sure window-resize retains the last page seen.

You can always use scrollTo, scroll bar or not, there is no restriction.

<Parallax
    ref={ref => this.parallax = ref}
    scrolling={false}
    ... >
    <Parallax.Layer>
        <div onClick={() => this.parallax.scrollTo(1)}>
            Click to get to the next page

Does it scroll horizontally as well?

Sure does.

<Parallax horizontal ... >

react-springy-parallax's People

Contributors

drcmda avatar storybynumbers 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

react-springy-parallax's Issues

Longer page

The last page of my app needs to be longer than the screen size. Is it possible to achieve this?

'Using this.refs is deprecated. (react/no-string-refs)' source: 'eslint'

Hi, love this, I'm just getting started out with react and I'm not sure how to use this with this.refs.parallax.scrollTo

Do I need to add it into the constructor?
image

I have just used the example code with some light editing

So, how do I use it?

Do I need to do it with a stateless function?

Thanks again

Source for demo?

Is this available to see anywhere? Trying to understand how to use multi-layers. That would be great if so :)

Once any link from page is clicked - the scroll is engaded

Hi!
I've found one specific issue.
Once any added to parallax layer link is clicked - the scroll to next layer is engaged. Right now I'm implementing modal-dialog which is accessed through links. So app behaves in such way:

  • click on link
  • the layer shifts and background colour is shown (related to fist page) | the layer is shifted to next one(non first layer)
  • modal is shown, but the page is reloads! Seems that this behaviour related also to first slide

How could it be fixed? Could the behaviour of internal links changed to ignore scroll action?

Server rendering :-/

Layers content completely disappears being rendered on a server :-( It comes to a client as an empty div. Next, on a client everything is fine.

Is there any way to let search engines to index layers content?

Example doesn't work in create-react-app

There's an error when I try to run the example in a default create-react-app. This may be due because of create-react-app, I didn't try it yet. However, so many people are using create-react-app and I thought that it might be fixed.

Error:

Uncaught Error: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

Reproduce:

Installation

create-react-app example2
cd example2

npm i react-springy-parallax -S

# edit App.js
# to add code from your example/index.js (like below)

npm start

create-react-app App.js

import React, { Component } from 'react';
import './App.css';

import Parallax from 'react-springy-parallax';

const styles = {
  fontFamily: 'Menlo-Regular, Menlo, monospace',
  fontSize: 14,
  lineHeight: '10px',
  color: 'white',
  display: 'flex', alignItems: 'center', justifyContent: 'center'
}

class App extends Component {
  render() {
    return (
      <div className="App">
        <Parallax ref="parallax" pages={3}>

          <Parallax.Layer offset={0} speed={1} style={{ backgroundColor: '#243B4A' }} />
          <Parallax.Layer offset={1} speed={1} style={{ backgroundColor: '#805E73' }} />
          <Parallax.Layer offset={2} speed={1} style={{ backgroundColor: '#87BCDE' }} />

          <Parallax.Layer
            offset={0}
            speed={0.5}
            style={styles}
            onClick={() => this.refs.parallax.scrollTo(1)}>
            Click!>
          </Parallax.Layer>

          <Parallax.Layer
            offset={1}
            speed={-0.1}
            style={styles}
            onClick={() => this.refs.parallax.scrollTo(2)}>
            Another page ...
          </Parallax.Layer>

          <Parallax.Layer
            offset={2}
            speed={0.5}
            style={styles}
            onClick={() => this.refs.parallax.scrollTo(0)}>
            The end.
          </Parallax.Layer>

        </Parallax>
      </div>
    );
  }
}

export default App;

Adjust Width of Page.

I have the following structure for my code:

<Parallax>
  <div className="wrapper">
    <Parallax.Layer>...</Parallax.Layer>
    <Parallax.Layer>...</Parallax.Layer>
    <Parallax.Layer>...</Parallax.Layer>
  </div>
</Parallax>

The div with class wrapper has a width property, but inside Parallax it doesn't work. I have set width: 85vw, but it's not working. What should I do to get it to work?

Suggestions for Responsive/Mobile

Hey,

Using react-springy-parallax works great most of the time on desktop. However, on mobile much of the content in the parallax is cutoff. Any suggestions for using this on mobile?

Does this work horizontally?

Can the parallaxes be set to be side by side and to be moved from left to right(& viceversa) on clicks(/ horizontal scroll)?

Break with react 15.4.4 using next.js (CSSPropertyOperations module not found error)

Runs okay in dev, breaks with next build

{ [Error: ./~/react-springy-parallax/~/animated/lib/targets/react-dom.js
Module not found: Error: Can't resolve 'react-dom/lib/CSSPropertyOperations' in '/home/ubuntu/deemx/node_modules/react-springy-parallax/node_modules/animated/lib/targets'

can this error be solved with a simple workaround ?

How the animation could be edited and controlled?

Hi!
Could you please explain more about how to use animation with you library?
In you sample:

<img
     src={url('server')}
     style={{ width: '20%', transform: [{ scale: this.animation }] }}
   />

is this.animation pre-difined value?
How different animations could be used? such as bounce-in, rotation, spin?
I've tried this:

style={{
          transform: [{rotate: spin}] }}

But spin is undefined.

Thank you very much
P.S. I've glanced at http://browniefed.com/react-native-animation-book/ but it looks like more advanced examples

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.