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 id="wrapApple">
     <img id="apple" src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/174563/apple.png' alt=''>
</div>


<section id="one">
  
</section>

<section id="two">
  <h2>I´m an APPLE!</h1>
</section>

<section id="three">
  <h2 id="small">A small one.</h1>
</section>

<section id="four">
  <h2>See you!</h1>
</section>


              
            
!

CSS

              
                body{
  background:grey;
  height:500vh;
}
#wrapApple{
  position:fixed;
  width:100%;
  height:100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index:1;
}
#apple{
  
}
section{
  position:relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width:100%;
  height:100vh;
  font-family:sans-serif;
  font-size:7w;
  font-size: 8vw;
  color: #a7a2a2;
  z-index:2;
}
              
            
!

JS

              
                
console.clear();


const options = {
  root: null,
  rootMargin: '0px',
  threshold: Array(100).fill().map((v, i) => i / 100) // important calling 100 times
  // threshold: 1, // calling callback only once when 100% visible
  //threshold: 0, // calling callback only once when 1px visible
  //threshold: [0.2, 0.4, 0.6, 0.8, 1.0], // calling callback 5 times
};
const observer = new IntersectionObserver(animHandler, options);
const targets = document.querySelectorAll("section");
const ar = [].slice.call(targets); 
let animations = [];


let count = 0;
//animations[1] = new TimelineMax({paused:true});  

for (let target of ar) {
  animations[count] = new TimelineMax({paused:true});  
  observer.observe(target);
  count++;
}

// timeline for each section
animations[0]

animations[1].to("#apple",1, {scale:1.4, ease: Sine.easeOut});

animations[2].to("#apple",1, {scale:0.4, ease: Sine.easeOut})
  .to('#small',1,{scale:0.5, transformOrigin:"center"},0)
  .to("#apple, #small",1, {scale:1, ease: Sine.easeOut})

animations[3].to("#apple",5, {rotation:360, ease: Sine.easeOut});

// observer handler
function animHandler(targets, observer) {
  for (var entry of targets) {
    if (entry.isIntersecting) {
      let i = ar.indexOf(entry.target);
      animations.forEach(tl => tl.pause(0));
      
      let isRatio = entry.intersectionRatio;
      //play the progress of the animations in relation to intersectionRatio
      TweenLite.to(animations[i], 0, {progress:isRatio, ease: Power0.easeNone});
 
    } 
  }
}
              
            
!
999px

Console