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

              
                 <nav id="nav" class="centered"></nav>

  <svg  class="go go-next" width="32" height="55" viewBox="0 0 40 55">
    <polyline points="3 3 30 28 3 53"></polyline>
  </svg>

  <svg  class="go go-prev" viewBox="0 0 40 55">
    <polyline points="28 3 3 28 28 53"></polyline>
  </svg> 
  
<div class="slides-container">
  
  <div class="slide" id="slide01">
    <h2 class="lines">An APPLE per day<br> 
    keeps the code clean!</h2>
  </div>

  <div class="slide" id="slide02">
    
    <img class="apple apple01 centered" src='https://assets.codepen.io/174563/greenApple.png' alt=''>
    <img class="apple apple02 centered" src='https://assets.codepen.io/174563/greenApple.png' alt=''>
    
    <div class="wrap centered">
    <h2 class="lines">Two APPLES per day ...<br>
      you become a MASTER!</h2>
    </div>

  </div>

  <div class="slide" id="slide03">
    <h2 class="lines">And you'll get <span>GREEN</span> socks</br>
  for smarter CODING!</h2>
	</div>

  <div class="slide" id="slide04">
	  <h2 class="lines">Join the GREENSOCK Club.</h2>
  </div>

</div>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
  font-family:sans-serif;
  background-color:black;
}

.go {
  width: 25px;
  stroke: #636363;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  z-index:12;
}
.go-prev, .go-next {
  position:absolute;
  cursor: pointer;
  top:50%;
  left: 5px;
  visibility:hidden;
}
.go-next {
  left:calc(100% - 32px)
}
h1, h2 {
  position:absolute;
  top:50%;
  width: 100%;
  font-weight: 800;
  font-size: clamp(1rem, 5vw, 3rem);
  margin: 0;
}
nav {
  position: absolute;
  bottom: 10px;
  left: 50%;
  width: inherit;
  z-index: 100;
  visibility: hidden;
}
.navDot{
  position: relative;
  width: 50px;
  height: 6px;
  background-color: black;
  opacity: 0.5;
  border-radius: 5px;
  border: 1px solid transparent;
  margin-right: 25px;
  float: left;
  cursor: pointer
}
.navDot:last-of-type{
  margin-right:0px;
}
/*
.navDot:hover{
  background-color: green;
  border: 1px solid black;
}
*/
.slides-container {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  z-index: 10;
}

.slide {
  position: absolute;
  top:0;
  left: 100%;
  width: 100%;
  height: 100%;
  text-align: center;
  background-color: grey;
  overflow: hidden;
}
.slide:nth-child(even){
  background-color: #0f8c0d;
  color: #333333;
}


#slide02 .wrap{
  position: absolute;
  top: 60%;
  left: 50%;
  width: 100%;
  text-align: center;
  height: 200px;
  overflow:hidden;
}
#slide04 h2{
  font-family: 'Orbitron', sans-serif;
}
.apple01{
  position: absolute;
  top: 54%;
  left: 40%;
  width: 96vh;
}
.apple02{
  position: absolute;
  top: 57%;
  left: 61%;
  width: 96vh;
}


              
            
!

JS

              
                console.clear();

let slides = gsap.utils.toArray(".slide"),
    currentIndex = 0,
    wrap = gsap.utils.wrap(0, slides.length), // - 1
    animating;

// ===================
gsap.set(".centered", {autoAlpha: 1, xPercent:-50, yPercent:-50});	
gsap.set("h1, h2", {autoAlpha: 1, yPercent:-50});	
gsap.set(".slide", {autoAlpha: 1});	
//gsap.set(".go", {autoAlpha: 1, yPercent:-50});	

// === navDots ==========
for( var i = 0; i < slides.length; i++ ) {

  let navDots = document.createElement("div"); 
  navDots.classList.add("navDot");
  document.getElementById("nav").appendChild(navDots);

};

let allNavDots = gsap.utils.toArray(".navDot");

// work in progress 
/*
allNavDots.forEach((dot, i) => {
  dot.addEventListener( "click", () => {

   
    if( i > currentIndex && !animating){
      gotoSlide(i, 1) 
    }

    if( i < currentIndex && !animating){
      gotoSlide(i, -1) 
    }

  });
})

gsap.set(allNavDots[0], { opacity: 1, scale: 1.3, transformOrigin:'center'});

console.log(allNavDots);  
*/ //================


// individual animations per slide ======

const allSlides = [].slice.call(slides); 
let animations = [];

for(let [i] of allSlides.entries()) {
  animations[i] = gsap.timeline({});
}

animations[0]
  .from('#slide01 .lines', {y:30, autoAlpha:0, duration:1, delay:0.5})
  .reverse();

animations[1]
  .from('.apple', { xPercent: -500, duration: 0.6, ease: "elastic.out(0.5, 0.4)", stagger: -0.4 })
  .from('#slide02 .lines', { y:200, duration: 1, delay: 1 }, '-=1.5')
  .reverse();

animations[2]
  .from('#slide03 .lines', { y: 30, autoAlpha: 0, duration: 1})
  .to('#slide03 span', { color:'green', fontSize:'7vw'}, 0)
  .reverse();

animations[3]
  .from('#slide04 .lines', {scale:0.2, transformOrigin:'center', duration:2})
  .reverse();



// === main func ======

function gotoSlide(index, direction) {

  animating = true;
  //open.play();
  
  let dur = 1.5; // duration

  newSlide = gsap.timeline({
    defaults: {duration: dur, ease: "power1.inOut"},
    onComplete: () => animating = false,
  });

  if(direction === 1) {
    if (index > 0) {
      animations[index - 1].progress(0).reversed(true);
      gsap.to(allNavDots[index - 1], { opacity: 0.5, scale: 1 });
    }
    newSlide.to(slides[index], { xPercent: -100 },0)

      .add(animations[index].reversed(false), dur)

    gsap.to(allNavDots[index], { opacity: 1, scale: 1.3 });
  }

  if(direction === -1) {

    newSlide.to(slides[index + 1], { xPercent: 100 },0)
      .add(animations[index].reversed(false), dur)

    animations[index + 1].progress(0).reversed(true);

    gsap.to(allNavDots[index], { opacity: 1, scale: 1.3 });
    gsap.to(allNavDots[index + 1], { opacity: 0.5, scale: 1 });
  } 
  
  // =========
  /*
  if(index == 0) {
    gsap.set('.go-prev', {autoAlpha:0})
  } else {
    gsap.set('.go-prev', {autoAlpha:1})
  }
  if(index == slides.length-1) {
    gsap.set('.go-next', {autoAlpha:0})
  } else {
    gsap.set('.go-next', {autoAlpha:1})
  }
  console.log(currentIndex, index); 
  */ //===============
  
   currentIndex = index;
}

ScrollTrigger.observe({
  type: "wheel,touch",
  preventDefault: true,
  onUp: () => !animating && currentIndex > 0 && gotoSlide(currentIndex - 1, -1),
  onDown: () => !animating && currentIndex < slides.length - 1 && gotoSlide(currentIndex + 1, 1),
  tolerance: 100,
});

gotoSlide(0, 1);





              
            
!
999px

Console