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="parallax-container">
  <div class="box box-1 parallax" data-speed-x="200" data-speed-y="200"></div>
	<div class="box box-2 parallax" data-speed-x="80" data-speed-y="80"></div>
	<div class="box box-3 parallax" data-speed-x="30" data-speed-y="40"></div>			
</div>
              
            
!

CSS

              
                #parallax-container{
	position: relative;
	width: 100%;
	height: 100%;
	padding: 0px;
	margin: 0px;
}
			
  .box{
	  position: absolute;
		width: 200px;
		height: 200px;
	}
			
	  .box-1{
		  background-color: #df7b7b;
			top: 100px;
			left: 30%;
		}
				
		.box-2{
		  background-color: rgba(217,109,187,0.5);
			top: 120px;
			left: 40%;
		}
				
		.box-3{
		  background-color: rgba(13,98,189,0.5);
			top: 130px;
			left: 50%;
		}
              
            
!

JS

              
                $(function(){				
				
        /*
          Author: Chrysto Panayotov ( info@bassta.bg )
          For GreenSock forums user azuki
          License : http://bassta.bg/license/
          
        */
  
				var $parallaxContainer 	  = $("#parallax-container"); //our container
				var $parallaxItems		    = $parallaxContainer.find(".parallax");  //elements
				var fixer				          = 0.0008;		//experiment with the value
				
				$(document).on("mousemove", function(event){					
							
					var pageX =  event.pageX - ($parallaxContainer.width() * 0.5);  //get the mouseX - negative on left, positive on right
					var pageY =  event.pageY - ($parallaxContainer.height() * 0.5); //same here, get the y. use console.log(pageY) to see the values
					
          //here we move each item
					$parallaxItems.each(function(){
						
						var item 	= $(this);
						var speedX	= item.data("speed-x");  				
						var speedY	= item.data("speed-y");
						
            /*TweenLite.to(item, 0.5, {
							x: (item.position().left + pageX * speedX )*fixer,    //calculate the new X based on mouse position * speed 
							y: (item.position().top + pageY * speedY)*fixer
						});*/
            
            //or use set - not so smooth, but better performance
            TweenLite.set(item, {
							x: (item.position().left + pageX * speedX )*fixer,
							y: (item.position().top + pageY * speedY)*fixer
						});
						
					});
				});				
			});

              
            
!
999px

Console