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="wrapper">

	<div id="container">
	
        <div class="element" id="div1"></div>
        
        <div class="element" id="div2"></div>
        
        <div class="element" id="div3"></div>
    
    </div>
    
</div>
              
            
!

CSS

              
                body
{
	background:#000;
	margin:0;
}

#wrapper
{
	height:50px;
	width:200px;
	margin:100px;
	padding:5px;
	background:#999;
	overflow:hidden;
}

#container
{
	width:800px;
	position:relative;
}

#container:after
{
	content:'';
	clear:both;
	display:block;
}

.element
{
	height:50px;
	width:200px;
	position:relative;
	float:left;
	margin-right:20px;
}

.element:last-child
{
	margin-right:0;
}

#div1
{
	background:blue;
}

#div2
{
	background:red;
}

#div3
{
	background:green;
}
              
            
!

JS

              
                var container = $("div#container"),
	div1 = $("div#div1"),
	div2 = $("div#div2"),
	div3 = $("div#div3"),
	elements = $("div.element"),
	positionsArray = [],//this array will contain every element position before scale down
	inZoom = false;


$.each(elements, function(index, element)
{
	//we create an object with the element's ID and position
	//we use position to keep it relative to the parent and not the document
	//for more info check the following: https://api.jquery.com/position/
	var originalLeft = {'id':$(element).attr('id'),'positionLeft':$(element).position().left};
	//we add that particular position to the array
	positionsArray.push(originalLeft);
});

//we scale down the container and therefore it's children
TweenMax.set(container, {scale:.25, transformOrigin:'0 0'});

elements.click(function(e)
{
	//if the container remains scale down proceed
	if(!inZoom)
	{
		//we loop through the array with the objects
		for(var index in positionsArray)
		{
			//we chek if the ID of the element clicked matches any of the array
			//in order to see what index the ID corresponds to 
			if($(e.target).attr('id') == positionsArray[index].id)
			{
				//we use the index and retrieve the element's left position
				//and tween the container to the left in that amount but negative
				TweenMax.to(container, 1,{scale:1, left:(-positionsArray[index].positionLeft) });
				inZoom = true;//the element is zoomed
			}
		}
	}
	else
	{
		//we return everything to normal
		TweenMax.to(container, 1, {scale:.25, left:0});
		inZoom = false;
	}
});
              
            
!
999px

Console