Git Product home page Git Product logo

react-page-transitions's Introduction

react-page-transitions

DEMO!

Page tranistions for ReactJS based on VelocityJS library. Mobile friendly. High performance.

alt tag

Change log

1.2.0

  • You can pass className along with other params
	<PageContainer className="some-test-class">
	  <div>....</div>
	</PageContainer>
  • Simplifying method responsible for passing props to component.

1.1.0

  • Additional parameters easing and duration (kudos to @simon-johansson)
  • Additional parameter callback. Fired when animation is completed.

Getting Started

Install: npm install react-page-transitions

var React = require('react/addons');
var PageContainer = require('react-page-transitions');

var PageTest = React.createClass({

	render: function () {
		return (
			<PageContainer>
			  <div>....</div>
			</PageContainer>
    );
  }
});

module.exports = PageTest;

Params

You can use custom parameters to set start and end styles. In example:

render: function () {
	var startStyles = {
            'opacity': 0,
            'scale': .5
        };

        var endStyles = {
            'opacity': 1,
            'scale': 1
        };
        
        var duration = 1000;
    	var easing = 'easeInExpo';
    	var callback = function() {
    		alert('Done');
    	};
        
	return (
		<PageContainer
		        startStyles={startStyles}
		        endStyles={endStyles}
		        duration={duration}
		        easing={easing}
		        callback={callback}
		      >
			<div>....</div>
		</PageContainer>
	);
}

module.exports = PageTest;

Velocity currently doesn't support multiple hooks in one call so what I'm doing is:

  • Iterate through all keys and values in startStyles objects. Hook all of them.
  • Start Velocity animate with endStyles.

Without this parameters it will just go with defaults (TranslateX from 100% to 0).

Styles (CSS)

For mobile I suggest to use this so animation will be affecting whole page:

render: function () {
	return (
		<PageContainer>
		  <div className="content">....</div>
		</PageContainer>
body, .page-content, .content {
	position: absolute;
	top: 0;
	bottom: 0;
	right: 0;
	left: 0;
}

// For webkit scroll touch
.loaded-page.content {
	overflow: auto;
	-webkit-overflow-scrolling: touch;
	overflow-x: hidden;
}

How its working?

Component renders with display none property. On componentDidMount I'm using Velocity hook to set translateX -100% to the container. Add child component. Set display block. Start VelocityJS animation to translateX 0. After that I'm also adding loaded-page class to container in case you want to use webkit scroll touch.

react-page-transitions's People

Contributors

jaing avatar simon-johansson avatar

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.