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

              
                .scene.one
  h1 Scene One
  p (Click Anywhere to Transition Scene)
  
.scene.two
  h1 Scene Two
  p (Click Anywhere to Transition Scene)
              
            
!

CSS

              
                .scene {
  box-sizing: border-box;
  flex-direction: column;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  width: 100%;
  padding: 2em;
  
  &.one {
    background-color: #FF7C35;
  }
  
  &.two {
    display: none;
    background-color: #E31D65;
  }
}

h1 {
  margin: 0;
  font-size: 5em;
  text-align: center;
  
  .one & {
    color: lighten(#FF7C35, 15);
  }
  
  .two & {
    color: lighten(#E31D65, 15);
  }
}

p {
  color: rgba(#fff, 0.4);
  letter-spacing: 0.5px;
  font-weight: 500;
}
              
            
!

JS

              
                /*
When you load the page, you'll notice that 
the first tween of 'tlSceneTwo' is running
despite the parent timeline being 'paused'. 

In order to fix this, you must pause the 
children timelines and then play the nested
timelines when added.

It seems like this is a bug since this only
occurs when using a tween that takes '0' seconds.
If we changed it to some ms value (ie. 0.1), it 
no longer autoplays on load.
*/

const sceneOne = document.querySelector('.scene.one');
const sceneTwo = document.querySelector('.scene.two');

const tlSceneOne = new TimelineMax() // add {paused: true} to resolve issue
  .to('.scene.one h1', 1, {autoAlpha: 0, scale: 0.95, y: -20})
  .set('.scene.one', {display: 'none', immediateRender:false, onComplete: function() {
    console.log('Scene One Ran');
  }});

const tlSceneTwo = new TimelineMax() // add {paused: true} to resolve issue
  .set('.scene.two', {display: 'flex', immediateRender:false, onComplete: function() {
    console.log('Scene Two Ran');
  }})
  .fromTo('.scene.two h1', 1, {autoAlpha: 0, scale: 0.95, y: -20}, {autoAlpha: 1, scale: 1, y: 0}, 0);

const tl = new TimelineMax({paused: true})
  .add(tlSceneOne) // add .play() when pausing nested tween
  .add(tlSceneTwo); // add .play() when pausing nested tween

sceneOne.addEventListener('click', e => {
  e.preventDefault();
  tl.play();
})

sceneTwo.addEventListener('click', e => {
  e.preventDefault();
  tl.reverse();
})
    
              
            
!
999px

Console