Advertisement
RobsonAlexandre

JqueryUI Selectable + Droppable

Oct 7th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.80 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8" />
  5.         <title>jQuery UI Selectable + Droppable</title>
  6.         <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  7.         <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  8.         <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  9.         <link rel="stylesheet" href="/resources/demos/style.css" />
  10.         <style>
  11.             #feedback { font-size: 1.4em; }
  12.             #selectable .ui-selecting { background: #FECA40; }
  13.             #selectable .ui-selected { background: #F39814; color: white; }
  14.             #selectable { list-style-type: none; margin: 0; padding: 0; width: 770px; }
  15.             .selectable { margin: 3px; padding: 1px; float: left; width: 100px; height: 80px; font-size: 4em; text-align: center; }
  16.             ul { list-style-type: none; margin: 0; padding: 0; margin-bottom: 10px; }
  17.             li { margin: 5px; padding: 5px; width: 150px; }
  18.             .dropped { font-size: 1em; }
  19.         </style>
  20.         <script>
  21.             $(function() {
  22.                 $("#selectable").selectable({
  23.                     stop: function() {
  24.                         $(".ui-selected", this).each(function() {
  25.                             $(this).addClass("droppable");
  26.                         });
  27.                     }
  28.                 });
  29.                 $(".draggable").draggable({
  30.                     helper: "clone",
  31.                     revert: "invalid"
  32.                 });
  33.                 $(".droppable").droppable({
  34.                     accept: ".draggable",
  35.                     activeClass: "ui-state-hover",
  36.                     hoverClass: "ui-state-active",
  37.                     drop: function(event, ui) {
  38.                         $(this)
  39.                                 .addClass("ui-state-highlight dropped")
  40.                                 .find("p")
  41.                                 .html(ui.draggable.text());
  42.                     }
  43.                 });
  44.             });
  45.         </script>
  46.     </head>
  47.     <body>
  48.         <table>
  49.             <tr>
  50.                 <td>
  51.                     <ul>
  52.                         <?php for ($i = 1; $i < 11; $i++): ?>
  53.                             <li class="ui-state-default draggable">Item <?= $i ?></li>
  54.                         <? endfor; ?>
  55.                     </ul>
  56.                 </td>
  57.                 <td>
  58.                     <ol id="selectable">
  59.                         <?php for ($i = 1; $i < 32; $i++): ?>
  60.                             <li class="ui-state-default selectable">
  61.                                 <?= $i ?><p></p>
  62.                             </li>
  63.                         <? endfor; ?>
  64.                     </ol>
  65.                 </td>
  66.             </tr>
  67.         </table>
  68.     </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement