javascript - change div parent and arrange after drag and drop -
please can me these div s. need move them column using drag , drop. dragged , dropped need arrange them correctly in selected columns.
<head> <style type="text/css"> .header { background-color: #c0c0c0; height:70px; width:1308px; border: solid; border-width: 1px; ; } .columns { background: #c1c1c1; height:400px; width: 1308px; border: solid; border-width: 1px } .col { background: #c1c1c1; float:left; height:400px; width: 325px; border: solid; border-width: 1px; position: relative; } .box { background: #f0f0f0; cursor: move; margin-left: auto; margin-right:auto; margin-top:10px; height:100px; width: 200px; border: solid; border-width: 1px; } #box1 { background: #f0f0f0; cursor: move; margin-left: auto; margin-right:auto; margin-top:10px; height:100px; width: 200px; border: solid; border-width: 1px; margin-top: 3px; margin-left: 5px; } #box1.moveable { background:#333; border: solid; border-width: 1px; margin-left: auto; margin-right:auto; margin-top:10px; } #box2 { background: #f0f0f0; cursor: move; margin-left: auto; margin-right:auto; margin-top:10px; height:100px; width: 200px; border: solid; border-width: 1px; margin-top: 3px; margin-left: 5px; } #box2.moveable { background:#333; border: solid; border-width: 1px; margin-left: auto; margin-right:auto; margin-top:10px; } #box3 { background: #f0f0f0; cursor: move; margin-left: auto; margin-right:auto; margin-top:10px; height:100px; width: 200px; border: solid; border-width: 1px; margin-top: 3px; margin-left: 5px; } #box3.moveable { background:#333; border: solid; border-width: 1px; margin-left: auto; margin-right:auto; margin-top:10px; } #box4 { background: #f0f0f0; cursor: move; margin-left: auto; margin-right:auto; margin-top:10px; height:100px; width: 200px; border: solid; border-width: 1px; margin-top: 3px; margin-left: 5px; } #box4.moveable { background:#333; border: solid; border-width: 1px; margin-left: auto; margin-right:auto; margin-top:10px; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script> function startmove() { $(".movable").on("mousemove", function(event) { var thisx = event.pagex - $(this).width() / 2, thisy = event.pagey - $(this).height() / 2; $(".movable").offset({ left: thisx, top: thisy }); $(this.parent()).detach().css({ top: 0, left: 0 }).appendchild(); }); } $(document).ready(function() { $("#box1").on("mousedown", function() { $(this).addclass("movable"); startmove(); }).on("mouseup", function() { $(this).removeclass("movable"); console.log($(this).attr('id')); }); $("#box2").on("mousedown", function() { $(this).addclass("movable"); startmove(); }).on("mouseup", function() { $(this).removeclass("movable"); console.log($(this).attr('id')); }); $("#box3").on("mousedown", function() { $(this).addclass("movable"); startmove(); }).on("mouseup", function() { $(this).removeclass("movable"); console.log($(this).attr('id')); }); $("#box4").on("mousedown", function() { $(this).addclass("movable"); startmove(); }).on("mouseup", function() { $(this).removeclass("movable"); console.log($(this).attr('id')); }); });; </script> </head> <body> <div class="header"> <p style="text-align: center; font-size: 20px;">header</p> </div> <div class="columns"> <div class="col" id="column1"> <div class="box" id="box1"></div> <div class="box" id="box2"></div> </div> <div class="col" id="column2"> <div class="box" id="box3"></div> </div> <div class="col" id="column3"></div> <div class="col" id="column4"> <div class="box" id="box4"></div> </div> </div>
Comments
Post a Comment