Клонирование div-ов при перемещении
Добрый день!
Помогите разобраться с jQuery Есть в блока: 1-й содержит ячейки которые можно перемещать. 2-й должен принимать эти блоки Проблема появляется когда с первого блока поместил несколько ячеек во второй блок и попробовать их поменять местами. Оно выбранную ячейку клонирует и не сортирует. Я только изучаю JS и не могу найти как исправить:( Посмотреть в живую можно Здесь <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <script type="text/javascript" src="http://demosites.simplecoding.org/jquery_ui_drag_drop/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="http://demosites.simplecoding.org/jquery_ui_drag_drop/jquery-ui-1.8.custom.min.js"></script> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $(function() { $('.textBlock').draggable({ helper:'clone' }); $('#block2').droppable({ hoverClass: 'dropHere' ,drop: function(event, ui) { $(this).append($('<div class="textBlock2">' + ui.draggable.html() + '</div>')); } }); }); $(function() { $( ".bla1, .bla2" ).sortable({ connectWith: ".connectedSortable" }).disableSelection(); }); </script> <style> @charset "UTF-8"; body { font-family: Arial, sans-serif; font-size: 0.8em; } h1 { font-size: 1.2em; text-align: center; } .wrapper { width: 400px; margin: 20px auto; } #block1, #block2, #block3 { border: solid 1px #555555; margin: 10px; padding: 20px; -moz-border-radius: 5px; -webkit-border-radius: 5px; } .textBlock { border: solid 1px #333333; font-weight: bold; margin: 10px 0 5px 0; padding: 10px; text-align: center; background-color: #eeeeee; -moz-border-radius: 3px; -webkit-border-radius: 3px; } .textBlock2 { border: solid 1px #333333; font-weight: bold; margin: 10px 0 5px 0; padding: 10px; text-align: center; background-color: #eeeeee; -moz-border-radius: 3px; -webkit-border-radius: 3px; } .dropHere { background-color: #e7e7de; } .table_drop{ width: 400px; } </style> </head> <body> <div class="wrapper"> <table border="1" style="width: 900px" class=" connectedSortables"><tr><td style="width: 100px"> <div id="block1" class=" bla2 connectedSortables"> <div class="textBlock ui-state-default">Блок 1</div> <div class="textBlock ui-state-default">Блок 2</div> <div class="textBlock ui-state-default">Блок 3</div> <div class="textBlock ui-state-default">Блок 4</div> <div class="textBlock ui-state-default">Блок 5</div> <div class="textBlock ui-state-default">Блок 6</div> </div> </td><td> <div id="block2" class="bla1"> <div> </div> </div> </td></tr></table> </div> </body> </html> |
думаю вам нужно брать координаты объектов и сравнивать с перетаскиваемым объектом. и по определенным условиям уже и сортировать.. у вас идет метод append, ясен пень он добавляет в конец..
|
vahminator,
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>demo</title> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <style type='text/css'> body { font-family: Arial, sans-serif; font-size: 0.8em; } h1 { font-size: 1.2em; text-align: center; } .wrapper { width: 400px; margin: 20px auto; } #block1, #block2, #block3 { border: solid 1px #555555; margin: 10px; padding: 20px; -moz-border-radius: 5px; -webkit-border-radius: 5px; float: left; min-width: 100px; } .textBlock { border: solid 1px #333333; font-weight: bold; margin: 10px 0 5px 0; padding: 10px; text-align: center; background-color: #eeeeee; -moz-border-radius: 3px; -webkit-border-radius: 3px; } .dropHere { background-color: #e7e7de; } .table_drop{ width: 400px; } </style> <script type='text/javascript'> $(window).load(function(){ $('#block1 .textBlock').draggable({ helper:'clone', connectToSortable:"#block2" }); $("#block2").sortable() }); </script> </head> <body> <div class="wrapper"> <div id="block1" class="bla1 connectedSortable"> <div class="textBlock ui-state-default">Блок 1</div> <div class="textBlock ui-state-default">Блок 2</div> <div class="textBlock ui-state-default">Блок 3</div> <div class="textBlock ui-state-default">Блок 4</div> <div class="textBlock ui-state-default">Блок 5</div> <div class="textBlock ui-state-default">Блок 6</div> </div> <div id="block2" class="bla2"></div> </div> </body> </html> |
рони,
Большое спасибо! Я, оказывается, копал не в ту сторону. Ваш код намного меньше и приятней читать! Еще раз большое спасибо! |
Часовой пояс GMT +3, время: 19:16. |