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

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.

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="parent"><h1>This div is "fixed". Which causes the box nested in it to be "fixed" too. Drag the box to see that the draggable clone is not fixed when the page is scrolled.</h1>
	
    <div class="element"></div>
    <div class="newElement"></div>
  
	
	
</div>


<div id="cont"><h1 id="iText">  #
 --------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  This div is not "fixed". Scroll the page to check.  --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # </h1>

</div>






              
            
!

CSS

              
                
#parent
{
	border:solid 2px #fff;
	margin:50px;
	position:fixed;
	clear:both;
	min-height:300px;
	width: 100%;
	background-color: green;
	z-index:2;
}


.element, .newElement
{
	background:#CCC;
	border:solid 1px #0FF;
	position: absolute;
	width:100px;
	height:100px;
	margin:10px;
	float:left;
		
}
.newElement
{
  border:solid 1px blue;
  background:red;
  	z-index:1;
  opacity:0;
	
}


.dragged {
	
	position: absolute;
	
}




#cont {
	
z-index: 1;
}
















#iText {
  line-height: 100%;
  position: absolute;
  padding-right: 5%;
  padding-left: 5%;
  font-size: 400%;
  z-index: -1;
}

              
            
!

JS

              
                var parent = $("div#parent"),
	elements = $("div.element"),
	currentID = 0,
	newElements = $("div.newElement"),
	overlapThreshold = "99%",
	latest;


$.each(elements, function(index, element)
{
	$(element).attr('id','element'+index);
	currentID++;
	$(element).html('Element N°: ' + index);
});

$.each(newElements, function(index, element)
{
	$(element).attr('id','element'+currentID);
	currentID++;
	//create the draggable instance for the current element in the DOM
	createDraggable(element);
});//new element loop end

function addElement()
{
	var newElement = '<div class="newElement" id="element' + currentID + '"></div>';
	parent.append(newElement);
	newElements = $("div#element"+currentID)
	//create the draggable instance for the new element
	createDraggable(newElements);
	//update the ID number
	currentID++;
}

function createDraggable(element)
{
	Draggable.create($(element),
    {
	    type:'x,y',
	    
		
		onDragStart:function()
		{
			TweenMax.to(this.target, .2, {opacity:1});
			//add just one element
			if(!$(this.target).hasClass("dragged"))
			{
				addElement();
				$(this.target).addClass("dragged");
				
				$(this.target).prependTo("div#cont").css({'top': event.pageY -= 60,'left': event.pageX -= 60, 'z-index': 2});
			
			}

				
			
		},
		
		
		onDragEnd : function(){
			
			$(this.target).css({'z-index': 1});
              
    },
		
		
		
		
		
	});//draggable instance end
}
              
            
!
999px

Console