jQuery Drag-n-Drop issue -
jQuery Drag-n-Drop issue -
i have 2 div elements 1. div (id="draggable") & div (id="dropper"). each of them contains several div within them. want drag , drop kid draggable dropper. after did want move them around in dropper. far have managed things, can't accomplish lastly part. because kid draggable can move in whole document. can pls help me this?
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>new web project</title> <link href="css/jquery-ui-1.10.0.custom.css" rel="stylesheet" type="text/css"/> <link href="css/style.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="script/jquery-1.9.0.js"> </script> <script type="text/javascript" src="script/jquery-ui-1.10.0.custom.js"> </script> <script type="text/javascript" src="script/script.js"> </script> </head> <body> <div id="draggable" class="drop"> <h4>drag here</h4> <div id="wrapper1" class="floatleft">item1 </div> <div id="wrapper2" class="floatleft">item2 </div> <div id="wrapper3" class="floatleft">item3 </div> <div id="wrapper4" class="floatleft">item4 </div> </div> <div id="dropper" class="drop"> <h4>drop'em here</h4> <div class="floatleft">item1 </div> <div class="floatleft">item2 </div> <div class="floatleft">item3 </div> <div class="floatleft">item4 </div> </div> </body> #draggable{ height:100px; border-style:solid; border-bottom-color:black; margin-right: 10px; } .floatleft{ float:left; margin:10px 10px 10px 10px; border-style:solid; border-color: gray; cursor: pointer; } #dropper{ height: 80px; /*width: 50%;*/ border-style:solid; border-bottom-color:black; margin-right: 10px; } $(function(){ $("#draggable").each(function(){ $("#draggable div").draggable(); } ); $("#dropper").droppable( ); $("#dropper div").draggable({ containment: "parent" }); });
seems me expect dropped item automatically inserted in dom construction of droppable - that's not case. , that's why code doesn't give want. however, there's sortable plugin might you're looking for. fact dropped div integrated in target's dom construction makes easy meet requirement:
$("#draggable").sortable ({ connectwith: "#dropper", items: "> div" }); $("#dropper").sortable({ containment: "parent", items: "> div" }); click link see jsfiddle uses sortable plugin
jquery jquery-ui
Comments
Post a Comment