Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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 class="container">
  
  <div class="slide strawberries"></div>
  <div class="slide coffee"></div>
  <div class="slide raspberries"></div>
  
  <div class="line">
    <h1>Strawberries</h1>
    <h1>Coffee</h1>
    <h1>Raspberries</h1>
  </div>
  
</div>
              
            
!

CSS

              
                body{
  margin:0;
  background-color:grey;
  height:10000px;
}

.container{
  position:absolute;
  width:100%;
  height:100vh;
  visibility:hidden;
}

.slide{
  position:absolute;
  top:50%;
  width:50vw;
  height:100vh;
  margin-left:50%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.strawberries {
  background-image: url("https://unsplash.it/800/450?image=1080");
}
.coffee {
  background-image: url("https://unsplash.it/600/450?image=766");
}
.raspberries {
  background-image: url("https://unsplash.it/1000/450?image=889");
  background-position: bottom;
}
.player {
  background-image: url("https://assets.codepen.io/174563/adrian-korte-76051-unsplash.jpg");
  background-position: 80% bottom;
}

.line{
  position: absolute;
  top: 30vh;
  left:0;
  width: 40vw;
  height: 50px;
  background-color: grey;
}
h1{
  position: absolute;
  top: 0;
  left: 20px;
  margin:0;
  font-size: 6vw;
  font-family: sans-serif;
  font-weight: 800;
  color: #9c9c9c;
  opacity:0;
}

              
            
!

JS

              
                
console.clear();

var allSlides = gsap.utils.toArray(".slide");
gsap.set(allSlides, {yPercent:50});

var allLines = gsap.utils.toArray('.line h1');
gsap.set(allLines, {yPercent:100});

gsap.set('.container', {autoAlpha:1})


var dur = 1, 
    next = 1.5, //dur plus 0.5 = little delay
    fade = 0.3,
    tt = 3000; // 'total time' in px of scrub animation

// stagger slides and lines =====
var action = gsap.timeline({
  defaults:{
    ease:'none', 
    stagger:next
  },
  paused:true
})
.to(allSlides, {yPercent:-50, duration:dur})
.to(allLines, {yPercent:0, opacity:1, duration:fade},dur - fade)
.to(allLines, {yPercent:-100, opacity:0, duration:fade},dur*2)

//create an animation that starts when the first staggered item is visible and goes through when the last item is fully visible.
// an idea of CARL / Snorkl.tv

const slider = gsap.fromTo(action, {time:dur}, {time:action.duration()-dur, paused:true})

ScrollTrigger.create({
  trigger: '.container',
  start: 'top top',
  end: '+=' + tt,
  pin: true,
  animation: slider,
  scrub: 0.3
})



              
            
!
999px

Console