javascript - How to create more than one drop zones while drag enter using jquery? -
is there way generate more 1 drop zones on page while using drag , drop field or element container? example, if have container generate dynamically top, left, right, , bottom drop zones when field dropping on it. can have option format fields rows , columns wise. demo page. store field styles/settings database.
anyone come across this?
sure, use class dropzone selector (code based on https://jqueryui.com/droppable/ )
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jquery ui droppable - default functionality</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> <style> #draggable { width: 70px; height: 70px; padding: 0.5em; margin: 10px 10px 10px 0; border: 1px solid #000000} .droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; border: 1px solid #555555 } </style> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> <script> $(function() { $("#draggable").draggable(); $(".droppable").droppable({ drop: function( event, ui ) { // detect dropzone object dropped var index = $(".droppable").index(this); $( ) .addclass( "ui-state-highlight" ) .find( "p" ) .html( "dropped in box index: " + index); } }); }); </script> </head> <body> <div id="draggable" class="ui-widget-content"> <p>drag me target</p> </div> <div class="droppable" class="ui-widget-header"> <p>drop here</p> </div> <div class="droppable" class="ui-widget-header"> <p>no, drop here</p> </div> <div class="droppable" class="ui-widget-header"> <p>rather, drop here</p> </div> <div class="droppable" class="ui-widget-header"> <p>you should drop here</p> </div> </body> </html>
Comments
Post a Comment