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

              
                <!--The Tutorial and propably best + easiest way to do Parallax Scrolling on many devices and many elements fast!: http://www.franckmaurin.com/the-parallax-effects-with-jquery/-->
<!--My (Jonathan Arbely) version of Franck Maurin's tutorial code has added comments, multiple sections instead of one and is tested on many, many devices: http://www.jonathanarbely.de-->
<!--Tested on: IE 6-11, FF 20-32, Safari 5-8, Chrome 28-37, Opera 24, iOS 6-8, Android 4: http://www.profi-homepage.de/ ...-->
<!--Next Version will include a "snap to parent" option, a beter way to animate and custom animations like rotate and transform-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Straightforward JQuery noPlugin Parallax Scrolling</title>
<meta name="author" content="Franck Maurin, Jonathan Arbely">
<!--JQuery 1.x will work on IE 6, 7 and 8-->
<script src="http://jonathanarbely.de/cdn/parallax/jquery-1.11.1.js"></script>
</head>

<body onLoad="pluginload();">
<div class="area1">
<div class="section element1"></div>
<div class="section element2"></div>
<div class="section element3"></div> 
</div>
<div class="area2">
<div class="section element4"></div>
<div class="section element5"></div>
<div class="section element6"></div>
</div>
<div class="area1">
<div class="section element7"></div>
<div class="section element8"></div>
<div class="section element9"></div>
</div>
</body>
              
            
!

CSS

              
                /*Three areas, each 1200px, in total 3600px, note the delay when I'm calling elements in js*/
html, body { height: 3600px; width: 100%; margin: 0; padding: 0; left: 0; top: 0; }
.area1 { background: #2b2b2b; height: 1200px; }
.area2 { background: #c12235; height: 1200px; }
div { overflow: hidden; }
.section { float: left; width:33.33%; height: 1200px; background:url(http://jonathanarbely.de/cdn/parallax/tri.png) no-repeat; }
.area2 .section { background:url(http://jonathanarbely.de/cdn/parallax/tri2.png) no-repeat; }:
              
            
!

JS

              
                // Function to call the plugin and the callers AFTER DOM load
function pluginload()  {
// The plugin code
// Known issues and behaviours: 
// IOS fires y scroller position only on touchcancel which causes stuttering.
// Stuttering under Android 4.x is hardware related, chrome works smoother
// Windows Phone 7 same as iOS, Windows Phone 8 same as Android
(function($){
	// Creates new Function "parallax" that receives up to three inputs (start, stop, coeff)
    $.fn.parallax = function(input){
		// New var is the targetet element
        var targetelement = $(this);
		// Get "targetelement" coordinates relative to document
        offset = targetelement.offset();
        // Create object containing four vars
		var defaults = {
            "start": 0, // Where the element should begin to scroll in px, not recommended
            "stop": offset.top + targetelement.height(), // Where the element shall stop scrolling in px, not recommended
            "coeff": 1, // Scroll speed (1 is default), can be + or -
			"delay": 0 // Instead of "start", when the element should start scrolling in px
        };
		// Handle default and input options, .extend merges to objects together to new object "opts", first object "defaults" is overwritten by second object with user input "input"
        var opts = $.extend(defaults, input);
		// freaking magic
        return this.each(function(){
			// more magic
            $(window).bind('scroll', function() {
				// new var "windowTop" is the difference between the current vertical position of the scrollbar "scrollTop" and user defined "delay"
                windowTop = $(window).scrollTop()-defaults.delay/*+150*/; // real start delay
                // if "targetelement" is between user defined start and stop, apply animation
				if((windowTop >= opts.start) && (windowTop <= opts.stop)) {
					// var "newCoord" defines the new coordinates for "targetelement" and is created by multiplying the current vertical position of the scrollbar with user defined animation speed 
                    newCoord = windowTop * opts.coeff;
					// Apply the new coordinates to "targetelement" css "background-position"
                    targetelement.css({
                        "background-position": "0 "+ newCoord + "px"
                    });
                }
            });
        });
    };
})(jQuery);

// call the plugin for any desired element (call with .class)
$('.element1').parallax({ "coeff":2, "delay":0 });
$('.element3').parallax({ "coeff":1.2, "delay":0 });
$('.element2').parallax({ "coeff":4.55, "delay":0 });
$('.element4').parallax({ "coeff":0.2, "delay":1200 });
$('.element5').parallax({ "coeff":1.2, "delay":1200 });
$('.element6').parallax({ "coeff":2.2, "delay":1200 });
$('.element7').parallax({ "coeff":-0.2, "delay":2400 });
$('.element8').parallax({ "coeff":-1.2, "delay":2400 });
$('.element9').parallax({ "coeff":8, "delay":2400 });
}
              
            
!
999px

Console