Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. import React, { PropTypes } from 'react';
  2.  
  3. // 1. animate pink slide
  4. // 2. animate white slide
  5. // 3. change zindex of view window to 13
  6. // 4. animate new content slide
  7. // 5. clear pink slide
  8. // 6. clear white slide
  9. // 7. reset zindex value of view window
  10.  
  11. const PageTransition = React.createClass({
  12. propTypes: {
  13. status: React.PropTypes.object,
  14. location: React.PropTypes.object,
  15. history: React.PropTypes.object,
  16. actions: React.PropTypes.object
  17. },
  18. contextTypes: {
  19. router: PropTypes.object,
  20. viewport: PropTypes.object
  21. },
  22. componentWillMount () {
  23. this.transitionTL = new TimelineLite();
  24. },
  25. componentWillReceiveProps (nextProps) {
  26. if (nextProps.status.startTransition && !this.props.status.startTransition) {
  27. this.animateIn(nextProps.status.path, nextProps.status.animationDirection);
  28. }
  29. if (!nextProps.status.startTransition && this.props.status.startTransition) {
  30. this.animateOut(nextProps.status.pageCtr, nextProps.status.animationDirection);
  31. }
  32. },
  33. getCurrentDocHeight () {
  34. const ctr = document.getElementsByClassName('page-container')[0];
  35. return ctr.getBoundingClientRect().height;
  36. },
  37. getCurrentWindowHeight () {
  38. return window.innerHeight;
  39. },
  40. getTransitionElementHeight () {
  41. return (this.getCurrentDocHeight() < this.getCurrentWindowHeight()) ? this.getCurrentWindowHeight() : this.getCurrentDocHeight();
  42. },
  43. leftTransTL (startOrigin) {
  44. const TL = new TimelineLite();
  45. TL.to(this.refs.transLeft, 1.2, {z: 0.0, scaleX: 1, transformOrigin: startOrigin, ease: Expo.easeInOut});
  46. return TL;
  47. },
  48. rightTransTL (startOrigin) {
  49. const TL = new TimelineLite();
  50. TL.to(this.refs.transRight, 1.5, {z: 0.0, zIndex:12, scaleX: 1, transformOrigin: startOrigin, ease: Expo.easeInOut});
  51. return TL;
  52. },
  53. leftTransTLOut (endOrigin) {
  54. const TL = new TimelineLite();
  55. TL.to(this.refs.transLeft, 0.25, {z: 0.0, scaleX: 0, transformOrigin: endOrigin, ease: Quart.easeInOut});
  56. return TL;
  57. },
  58. rightTransTLOut (endOrigin) {
  59. const TL = new TimelineLite();
  60. TL.to(this.refs.transRight, 0.25, {z: 0.0, scaleX: 0, transformOrigin: endOrigin, ease: Quart.easeInOut});
  61. return TL;
  62. },
  63. pageTransTL (pageEl, xStart) {
  64. const TL = new TimelineLite();
  65. TL.fromTo(pageEl, 0.8, {autoAlpha: 0, z: 0.0000}, {z: 0.0000, autoAlpha: 1, ease: Expo.easeInOut, onComplete: () => {
  66. TweenLite.set(pageEl, {clearProps: 'all'});
  67. }});
  68. return TL;
  69. },
  70. goToNewPath (path) {
  71. return () => this.context.router.push({state: {animateIn: true}, pathname: path});
  72. },
  73. animateIn (newPath, animDir) {
  74. const transOriginStart = (animDir === 'left') ? 'center left' : 'center right';
  75. this.transitionTL.set([this.refs.transLeft, this.refs.transRight], {height: this.getTransitionElementHeight()});
  76. this.transitionTL.addLabel('start');
  77. this.transitionTL.add(this.leftTransTL(transOriginStart), 'start');
  78. this.transitionTL.add(this.rightTransTL(transOriginStart), 'start');
  79. this.transitionTL.add(this.goToNewPath(newPath), 'start+=0.8');
  80. },
  81. animateOut (pageEl, animDir) {
  82. const xStart = (animDir === 'left') ? -130 : 130;
  83. this.transitionTL.set([this.refs.transLeft, this.refs.transRight], {height: this.getTransitionElementHeight(), xPercent: 0, scaleX: 0});
  84.  
  85. if (pageEl) {
  86. TweenLite.set(pageEl, {position: 'relative', zIndex: 13});
  87.  
  88. this.transitionTL.add(this.pageTransTL(pageEl, xStart), 'start+=0.65');
  89. }
  90. },
  91. render () {
  92. return (
  93. <div className='transition' ref='transitionEl'>
  94. <div ref='transRight' className='transition-right'></div>
  95. <div ref='transLeft' className='transition-left' style={{backgroundColor: '#fff'}}></div>
  96. </div>
  97. );
  98. }
  99. });
  100.  
  101. export default PageTransition;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement