cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <header>
  <div id="box1"></div>
  <div id="box2"></div>
  <div id="box3"></div>
</header>
            
          
!
            
              body {
	min-height:2000px;
}

header {
	position:absolute;
	top:0;
	left:0;
	width:100%;
	height:500px;
	background-color:#e7e7e7;
  overflow: hidden;
}

div[id^=box]{
  position: absolute;
}

#box1 {
	left:10%;
	bottom:20%;
	width:300px;
	height:300px;
	background-color:red;
}

#box2 {
	top:10%;
	left:40%;
	width:200px;
	height:130px;
	background-color:#000;
}

#box3 {
	top:30%;
	right:20%;
	width:12%;
	height:17%;
	background-color:green;
}
            
          
!
            
              document.addEventListener("DOMContentLoaded", function(){
				
  //needed to get scrollTop position on IE9-
  var documentElement = document.documentElement;
  
  //Heder height
  var targetPosY = 500;
  
  /*
      A couple of notes here 
      1)   For such a thing, normally I would just use a TimelineMax. It is amazingly flexible and is tend for just this kind of animations. 
           The idea of this pen is to make things fast and simple as possible;
      2)   Actually, I can pass string to TweenLite.to("element ID", time, {...}); but I prefer to pass DOM Element
      3)   If you add your own TweenLite's and style it, actually can get pritty nice results
  */
  var tweens = [
     TweenLite.to( document.querySelector("#box1"), 1, {css:{force3D:true, scale:1.2, y:100}, paused:true}),
     TweenLite.to( document.querySelector("#box2"), 1, {css:{force3D:true, scale:1.6, y:200, x:-100, alpha: 0.5}, paused:true}),
     TweenLite.to( document.querySelector("#box3"), 1, {css:{force3D:true, scale:2.6, y:150, x:50, rotation:45}, paused:true})
  ];
				
  window.onscroll = function (event) {
    ( !! window.requestAnimationFrame) ? requestAnimationFrame(onScroll) : onScroll();
  }
				 
  function onScroll(){
	    
      //have to restrict it into range, because on OSX it can get negative values
      //http://bassta.bg/2013/05/restrict-a-number-to-a-range/
	    var top =  Math.max(Math.min(window.pageYOffset || documentElement.scrollTop, targetPosY), 0); 
	    if(top <= targetPosY){
	        var progress = (top / targetPosY);
	        Array.prototype.forEach.call(tweens, function(tween){
		        tween.progress(progress);
		      });
	    }
  }
									
});//end on DOMContentLoaded
            
          
!
999px
Loading ..................

Console