Full Page Menu Transition (React, Greensock)

In this example below you will see how to do a Full Page Menu Transition (React, Greensock) with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 01fade, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 01fade ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Full Page Menu Transition (React, Greensock)</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id="App">
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/TweenMax.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/01fade/full-page-menu-transition-react-greensock-QvBoRg */
body {
  margin: 0;
  font-family: sans-serif;
}

#content {
  position: fixed;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#projects {
  position: relative;
  height: 100%;
  width: 100%;
  margin-left: 0%;
}

.proj-container {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
}

.content {
  width: 940px;
  height: 100%;
  position: relative;
  left: 0;
  right: 0;
  margin: 0 auto;
  padding: 20px;
}

.menu,
#sliding-menu {
  box-sizing: border-box;
  padding: 20px;
  color: #FFF;
  width: 150px;
  height: 100%;
  position: absolute;
}

#multimedia .content {
  padding-left: 60px;
}
#multimedia .menu {
  right: 0;
}

#ux .content {
  padding-left: 140px;
}
#ux .menu {
  left: 0;
}

#sliding-menu {
  background-color: blue;
}


/*Downloaded from https://www.codeseek.co/01fade/full-page-menu-transition-react-greensock-QvBoRg */
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Counter = function (_React$Component) {
	_inherits(Counter, _React$Component);

	function Counter(props) {
		_classCallCheck(this, Counter);

		var _this = _possibleConstructorReturn(this, (Counter.__proto__ || Object.getPrototypeOf(Counter)).call(this, props));

		_this.state = { cat: "multimedia" };
		return _this;
	}

	_createClass(Counter, [{
		key: "slide",
		value: function slide(cat, e) {
			var currentEl = document.getElementById(e.target.parentNode.id);
			var nextEl = document.getElementById(cat);
			var animEl = document.getElementById("sliding-menu");
			// EDIT 
			// duration, "key frames", easing
			// easing functions https://greensock.com/ease-visualizer
			//
			TweenMax.to(currentEl, 0.2, { // duration of fading out the current content
				opacity: 0,
				zIndex: -1,
				ease: Sine.easeIn // easing
			});
			TweenMax.to(animEl, 0.2, { // duration of expanding the blue box
				delay: 0.4, // key time in timeline when this should start, think of it as a key frame
				width: "100%",
				ease: Power4.easeInOut, // easing
				onComplete: function onComplete() {
					if (cat === "multimedia") {
						animEl.style.right = 0;
						animEl.style.left = "auto";
					} else {
						animEl.style.right = "auto";
						animEl.style.left = 0;
					}
				}
			});
			TweenMax.to(animEl, 0.2, { // duration of collapsing the blue box back to 150px
				delay: 0.8, // key time in timeline when this should start, think of it as a key frame
				width: 150,
				ease: Power4.easeInOut // easing
			});
			TweenMax.to(nextEl, 0.2, { // duration for the new content to fade in
				delay: 1, // key time in timeline when this should start, think of it as a key frame
				opacity: 1,
				zIndex: 1000,
				ease: Sine.easeIn // easing
			});
		}
	}, {
		key: "render",
		value: function render() {
			var multimedia = this.state.cat === "multimedia" ? true : false;
			var slidingPos = multimedia ? { right: 0 } : { left: 0 };
			var uxStyle = multimedia ? { opacity: 0, zIndex: -1 } : {};
			var multiStyle = multimedia ? {} : { opacity: 0, zIndex: -1 };

			return React.createElement(
				"div",
				{ id: "content" },
				React.createElement("div", { id: "sliding-menu", style: slidingPos }),
				React.createElement(
					"div",
					{ id: "projects" },
					React.createElement(
						"div",
						{ id: "multimedia", className: "proj-container", style: multiStyle },
						React.createElement(
							"div",
							{ className: "menu", onClick: this.slide.bind(this, "ux") },
							"UX ",
							React.createElement("br", null),
							"Menu"
						),
						React.createElement(
							"div",
							{ className: "content" },
							"Multimedia Projects"
						)
					),
					React.createElement(
						"div",
						{ id: "ux", className: "proj-container", style: uxStyle },
						React.createElement(
							"div",
							{ className: "menu", onClick: this.slide.bind(this, "multimedia") },
							"Multimedia Menu"
						),
						React.createElement(
							"div",
							{ className: "content" },
							"UX Projects"
						)
					)
				)
			);
		}
	}]);

	return Counter;
}(React.Component);

ReactDOM.render(React.createElement(Counter, null), document.getElementById("App"));

Comments