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" }
  ]
};

const menuTl = new TimelineMax({ paused: true, reversed: true });
const previewCaseTl = new TimelineMax();

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      menuActive: false,
      allProjects: Data.projects,
      csPreviewActive: false,
      activePanel: null
    };
    this.togglePreviewCase = this.togglePreviewCase.bind(this);
    this.previewCaseReverseHandler = this.previewCaseReverseHandler.bind(this);
    // store the timeline in the component because we need to access
    // a callback that's inside the component in the reverse complete event
    this.previewCaseTl = new TimelineMax({
      paused:true,
      onReverseComplete: this.previewCaseReverseHandler
    });
  }

  componentDidMount() {
    this.slideMenu();
  }

  // bring the project to view//
  slideMenu = () => {
    var projects = document.getElementsByClassName("project");
    //transform the HTMLcollection to an array
    var projects = Array.from(projects);
    menuTl.set(".tomsah-project", { zIndex: 0 }).staggerTo(projects, 1, {
      cycle: { x: ["64%", "72%", "80%", "88%"] },
      ease: Power2.easeInOut
    });
    return menuTl;
  };

  toggleMenu = e => {
    e.preventDefault();
    menuTl.reversed() ? menuTl.play() : menuTl.reverse();
    this.setState({
      menuActive: !this.state.menuActive
    });
  };

  previewCase = id => {
    var element = `#${id}`;
    this.previewCaseTl
      .to(element, 1, { x: "0%", ease: Power2.easeInOut })
      .play();
  };

  togglePreviewCase = e => {
    
    const { activePanel } = this.state;
    const { id } = e.currentTarget;
    e.preventDefault();
    // first check if a panel is active
    if ( activePanel ) {
      // check if the id is the same of the active panel
      if ( activePanel === id ) {
        // the current panel is the active one, set the
        // state prop to null
        this.setState({ activePanel: null });
      } else {
        // the current panel is not the active
        this.setState({ activePanel: id });
      }
      // there's an active panel, reverse the timeline
      this.previewCaseTl.reverse();
    } else {
      // there's no active panel
      // set the active panel
      this.setState({ activePanel: id });
      // since there's no active panel the timeline is empty
      // add the instances to the timeline and play it
      this.previewCase(id);
    }
  };

  // the reverse complete callback
  // used to create the new instance of the panel tween
  // if there's an active panel
  previewCaseReverseHandler(){
    const { activePanel } = this.state;
    // if there's an active panelin the state, clear the timeline and
    // create a new instance with the active panel
    if ( activePanel ) {
      this.previewCaseTl.clear();
      this.previewCase(activePanel);
    } else {
      this.previewCaseTl.clear();
    }
  }

  render() {
    const { allProjects } = this.state;
    return (
      <div className="main">
        <button onClick={this.toggleMenu}> menu </button>
        <div className="projects" ref="projects">
          {allProjects.map((project, index) => {
            return (
              <div
                className="project"
                ref={`CaseStudy${index}`}
                key={index}
                id={`project-${index + 1}`}
                onClick={this.togglePreviewCase}
              >
                <span> {project.name} </span>
              </div>
            );
          })}
        </div>
      </div>
    );
  }
}

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

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

              
            
!
999px

Console