Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app"></div>
              
            
!

CSS

              
                body {
  background-color: #333;
}

button {
  z-index: 1;
  position: relative;
}

.projects {
  height: 100vh;
  position: fixed;
  width: 100%;
  top: 0;
}

.project{
  padding-top: 10px;
  background: white;
  color: black;
  height: 92vh;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  box-shadow: 0px -2px 10px 1px #403838;
  transform: translateX(100%);
  
        span {
        writing-mode: vertical-rl;
        margin-bottom: 20px;
        font-size: 18px;
        line-height: 1.8;
        transform: rotate(180deg);
      }
}

              
            
!

JS

              
                const Data = {
  projects: [
    { name: "project 1" },
    { name: "project 2" },
    { name: "project 3" },
    { name: "project 4" },
    { name: "project 5" }
  ]
};

class App extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      menuExpanded: false,
      targetPanel: null
    };
    
    // menu items
    this.menuItems = [];
    
    // menu tween
    this.menuTl = new TimelineLite({paused:true});
  }

  componentDidMount() {
    this.createMenuTween();
  }

  // bring the project to view//
  createMenuTween = () => {
    this.menuTl
      .staggerTo(this.menuItems, 1, {
        cycle: { x: ["56%","64%", "72%", "80%", "88%"] },
        ease: Power2.easeInOut
      })
      .reverse();
  };

  toggleMenu = e => {
    const { menuExpanded, targetPanel } = this.state;
    // if a panel is expanded, collapse any panel and then reverse
    // the menu timeline
    if ( targetPanel !== null ) {
      return TweenLite.to(
        this.menuItems.slice(0, targetPanel + 1), 1, {
          x: '+=50%', ease: Power2.easeInOut, onComplete: () =>{
            // toggle the state property
            this.setState({
              menuExpanded: !menuExpanded,
              targetPanel: null
            });
            this.menuTl.reversed( menuExpanded );
          }// on complete
      });// tweenlite instance
    }
    // toggle the state property
    this.setState({ menuExpanded: !menuExpanded });
    this.menuTl.reversed( menuExpanded );
  };
  
  // access the inde and the event object
  // the index will tell us which panel is being targeted
  // and create the animation based on that parameter
  togglePreviewCase = (index, e) => {
    const { menuItems } = this;
    const { targetPanel } = this.state;
    // create two arrays with the elements that should be animated
    // one for the elements that will be expanded and the ones that
    // will be collapsed
    let expandArray, collapseArray;
    // if the current target is null means no element is expanded
    if ( targetPanel === null ) {
      // only create an array for the elements that will be expanded
      expandArray = menuItems.slice(0, index + 1);
      TweenLite.to( expandArray, 1, {
        x: '-=50%', ease: Power2.easeInOut
      })
    } else if ( index < targetPanel ) {
      // the new target is already expanded, we have to collapse
      // the panels before that, there's no expand animation
      collapseArray = menuItems.slice(index + 1, targetPanel + 1);
      TweenLite.to( collapseArray, 1, {
        x: '+=50%', ease: Power2.easeInOut
      });
    } else if ( index > targetPanel ) {
      // the new target is not expanded, we have to expand all the
      // elements between the previous target and the new one
      expandArray = menuItems.slice(targetPanel + 1, index + 1);
      TweenLite.to( expandArray, 1, {
        x: '-=50%', ease: Power2.easeInOut
      });
    } else if ( index === targetPanel ) {
      // the current target element is being clicked, reverse that
      TweenLite.to( menuItems[index], 1, {
        x: '+=50%', ease: Power2.easeInOut
      });
      // the new target index should be the previous element if the
      // index is bigger than 0
      return this.setState({ targetPanel: targetPanel > 0 ? targetPanel - 1 : null });
    }
    // set the current index as the target panel
    this.setState({ targetPanel: index });
  };

  render() {
    return (
      <div className="main">
        <button onClick={this.toggleMenu} id='toggleMenu'> menu </button>
        <div className="projects" ref="projects">
          {Data.projects.map((project, index) => {
            return (
              <div
                className="project"
                ref={ project => this.menuItems.push(project)}
                key={index}
                id={`project-${index + 1}`}
                onClick={this.togglePreviewCase.bind(null, index)}
              >
                <span> {project.name} </span>
              </div>
            );
          })}
        </div>
      </div>
    );
  }
}

/*
 * Render the above component into the div#app
 */

ReactDOM.render(<App />, document.getElementById("app"));

              
            
!
999px

Console