Draggable add element

Developer
Size
2,642 Kb
Views
22,264

How do I make an draggable add element?

Http://forums.greensock.com/topic/8248-drag-new-element-from-the-div/. What is a draggable add element? How do you make a draggable add element? This script and codes were developed by Eduard L. on 15 October 2022, Saturday.

Draggable add element Previews

Draggable add element - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Draggable add element</title> <script src="https://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="parent"> <div class="element"></div> <div class="newElement"></div> <div style="clear:both;"></div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/utils/Draggable.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Draggable add element - Script Codes CSS Codes

body
{ margin:0px; padding:0px;	font-family: "Open Sans", arial;	background:url('http://wallpapersus.com/wallpapers/2012/06/abstract-blurry-creative-gaussian-blur-720x1152.jpg');	color:#fff;	font-weight:300;
}
#parent
{	border:solid 1px #fff;	margin:50px;	position:relative;	clear:both;	height:500px;
}
.element, .newElement
{	position:absolute;	width:100px;	height:100px;	margin:10px;	float:left;	z-index:10;
boder:solid 1px #f9f9f9; -webkit-box-shadow: 0px 0px 7px 0px rgba(50, 50, 50, 0.26);
-moz-box-shadow: 0px 0px 7px 0px rgba(50, 50, 50, 0.26);
box-shadow: 0px 0px 7px 0px rgba(50, 50, 50, 0.26);
}
.newElement
{ border: 1px blue #f0edf0; background:#ebebeb; z-index:100; opacity:0;
border: 1px solid #f0edf0;
-webkit-box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
-moz-box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
} .newElement:hover
{	position:absolute;	width:120px;	height:120px;	margin:0px;	float:right;	z-index:10;
border: 1px solid #f0edf0;
-webkit-box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
-moz-box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
-webkit-transition:all .2s;
-webkit-transition-timing-function:gradient;
}
.element:active, .newElement:active
{	position:absolute;	width:100px;	height:100px;	margin:10px;	float:right;	z-index:10;
border: 1px solid #f0edf0;
-webkit-box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
-moz-box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
box-shadow: 3px 3px 9px 0px rgba(50, 50, 50, 0.32);
}

Draggable add element - Script Codes JS Codes

var parent = $("div#parent"),	elements = $("div.element"),	currentID = 0,	newElements = $("div.newElement"),	latest;
$.each(elements, function(index, element)
{	$(element).attr('id','element'+index);	currentID++;	$(element).html('Create Icon: ');
});
$.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', bounds:'#parent',	edgeResistance:0.85,	onDragStart:function()	{	TweenMax.to(this.target, .2, {opacity:1});	//add just one element	if(!$(this.target).hasClass("dragged"))	{	addElement();	$(this.target).addClass("dragged");	}	}	});//draggable instance end
}
Draggable add element - Script Codes
Draggable add element - Script Codes
Home Page Home
Developer Eduard L.
Username EduardL
Uploaded October 15, 2022
Rating 3
Size 2,642 Kb
Views 22,264
Do you need developer help for Draggable add element?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Eduard L. (EduardL) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!