Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15108
  • 博文数量: 11
  • 博客积分: 130
  • 博客等级: 入伍新兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-07 13:21
文章分类

全部博文(11)

文章存档

2015年(1)

2014年(5)

2011年(5)

我的朋友
最近访客

分类: Web开发

2014-11-01 07:47:41

dd.zip

点击(此处)折叠或打开


  1. <html>
  2. <head>
  3.     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

  4.     <title>ExtJS.com Drag and Drop with DOM Elements</title>
  5.     <link rel="stylesheet" href="/resources/ext-theme-gray/ext-theme-gray-all.css" />
  6.     <script src="/extjs/ext-all-debug.js"></script>
  7.     <style type="text/css">
  8.         body {
  9.             padding: 10px;
  10.         }

  11.         .availableLot {
  12.             width: 105px;
  13.             border: 1px solid #999999;
  14.             padding: 10px;
  15.             height: 290px;
  16.             -moz-border-radius: 17px;
  17.             -webkit-border-radius: 17px;

  18.         }

  19.         .rented, .repair {
  20.             width: 195px;
  21.         }

  22.         .availableLot div {
  23.             -moz-border-radius: 5px;
  24.             -webkit-border-radius: 5px;
  25.             width: 85px;
  26.             border: 1px solid #666666;
  27.             padding: 3px;
  28.             background-color: #FFFFFF;
  29.             margin: 5px;
  30.             cursor: move;
  31.             text-align: center;
  32.         }

  33.         #cars div, #trucks div {
  34.             margin: 5px;
  35.             width: 85px;
  36.         }

  37.         #repair div, #rented div {
  38.             float: left;
  39.             margin: 2px;
  40.             /*padding: 3px;*/

  41.         }

  42.         .imgThumb {
  43.             height: 57px;
  44.             width: 77px;
  45.             border: 1px solid #777777;
  46.         }

  47.         .dropOK {
  48.             background-color: #99ff99 !important;
  49.         }

  50.         .dropNotOK {
  51.             border: 1px solid #FF0000 !important;
  52.         }
  53.     </style>

  54.     
  55. </head>
  56. <body>
  57. <table class="x-unselectable">
  58.     <tbody>
  59.     <tr>
  60.         <td align="center" style="width: 200px;">
  61.             <table>
  62.                 <tbody>
  63.                 <tr>
  64.                     <td align="center" style="width: 200px;">
  65.                         Vehicles Rented
  66.                     </td>
  67.                     <td align="center" style="width: 200px;">
  68.                         Vehicles In Repair
  69.                     </td>
  70.                 </tr>
  71.                 <tr style="">
  72.                     <td style="">
  73.                         <div id="rented" class="availableLot rented">
  74.                             <div><img src="" class="imgThumb"
  75.                                       qtip="S10"></div>
  76.                         </div>
  77.                     </td>
  78.                     <td>
  79.                         <div id="repair" class="availableLot repair"></div>
  80.                     </td>
  81.                 </tr>

  82.                 </tbody>
  83.             </table>
  84.         </td>
  85.         <td>
  86.             <table>
  87.                 <tbody>
  88.                 <tr>
  89.                     <td align="center">
  90.                         Available Cars
  91.                     </td>
  92.                     <td align="center">
  93.                         Available Trucks
  94.                     </td>
  95.                 </tr>


  96.                 <tr>
  97.                     <td>
  98.                         <div id="cars" class="availableLot">
  99.                             <div><img src="./ExtJS.com Drag and Drop with DOM Elements_files/camaro.jpg"
  100.                                       class="imgThumb" qtip="Camaro"></div>
  101.                             <div><img src="./ExtJS.com Drag and Drop with DOM Elements_files/miata.jpg" class="imgThumb"
  102.                                       qtip="Miata"></div>
  103.                             <div><img src="./ExtJS.com Drag and Drop with DOM Elements_files/mustang.jpg"
  104.                                       class="imgThumb" qtip="Mustang"></div>
  105.                             <div><img src="./ExtJS.com Drag and Drop with DOM Elements_files/corvette.jpg"
  106.                                       class="imgThumb" qtip="Corvette"></div>
  107.                         </div>
  108.                     </td>

  109.                     <td>
  110.                         <div id="trucks" class="availableLot trucksLot">
  111.                             <div><img src="./ExtJS.com Drag and Drop with DOM Elements_files/f150.jpg" class="imgThumb"
  112.                                       qtip="F150"></div>
  113.                             <div><img src="./ExtJS.com Drag and Drop with DOM Elements_files/tahoe.jpg" class="imgThumb"
  114.                                       qtip="Tahoe"></div>
  115.                             <div><img src="./ExtJS.com Drag and Drop with DOM Elements_files/tacoma.jpg"
  116.                                       class="imgThumb" qtip="Tacoma"></div>
  117.                             <div><img src="./ExtJS.com Drag and Drop with DOM Elements_files/s10.jpg" class="imgThumb"
  118.                                       qtip="S10"></div>
  119.                         </div>
  120.                     </td>
  121.                 </tr>

  122.                 </tbody>
  123.             </table>
  124.         </td>
  125.     </tr>
  126.     </tbody>
  127. </table>
  128. <script type="text/javascript">

  129.     Ext.onReady(function() {
  130.         // Create an object that we'll use to implement and override drag behaviors a little later
  131.         var overrides = {
  132.             // Called the instance the element is dragged.
  133.             b4StartDrag : function() {
  134.                 // Cache the drag element
  135.                 if (!this.el) {
  136.                     this.el = Ext.get(this.getEl());
  137.                 }

  138.                 //Cache the original XY Coordinates of the element, we'll use this later.
  139.                 this.originalXY = this.el.getXY();
  140.                 console.log(this.originalXY);
  141.             },
  142.             // Called when element is dropped not anything other than a dropzone with the same ddgroup
  143.             onInvalidDrop : function() {
  144.                 // Set a flag to invoke the animated repair
  145.                 this.invalidDrop = true;
  146.             },
  147.             // Called when the drag operation completes
  148.             endDrag : function() {
  149.                 // Invoke the animation if the invalidDrop flag is set to true
  150.                 if (this.invalidDrop === true) {
  151.                     // Remove the drop invitation
  152.                     this.el.removeCls('dropOK');

  153.                     // Create the animation configuration object
  154.                     var animCfgObj = {
  155.                         easing : 'elasticOut',
  156.                         duration : 1,
  157.                         scope : this,
  158.                         callback : function() {
  159.                             // Remove the position attribute
  160.                             this.el.dom.style.position = '';
  161.                         }
  162.                     };

  163.                     // Apply the repair animation
  164.                     this.el.moveTo(this.originalXY[0], this.originalXY[1], animCfgObj);
  165.                     delete this.invalidDrop;
  166.                 }
  167.             },

  168.             // Called upon successful drop of an element on a DDTarget with the same
  169.             onDragDrop : function(evtObj, targetElId) {
  170.                 // Wrap the drop target element with Ext.Element
  171.                 var dropEl = Ext.get(targetElId);

  172.                 // Perform the node move only if the drag element's
  173.                 // parent is not the same as the drop target
  174.                 if (this.el.dom.parentNode.id != targetElId) {

  175.                     // Move the element
  176.                     dropEl.appendChild(this.el);

  177.                     // Remove the drag invitation
  178.                     this.onDragOut(evtObj, targetElId);

  179.                     // Clear the styles
  180.                     this.el.dom.style.position ='';
  181.                     this.el.dom.style.top = '';
  182.                     this.el.dom.style.left = '';
  183.                 }
  184.                 else {
  185.                     // This was an invalid drop, initiate a repair
  186.                     this.onInvalidDrop();
  187.                 }
  188.             },

  189.             // Only called when the drag element is dragged over the a drop target with the same ddgroup
  190.             onDragEnter : function(evtObj, targetElId) {
  191.                 // Colorize the drag target if the drag node's parent is not the same as the drop target
  192.                 if (targetElId != this.el.dom.parentNode.id) {
  193.                     this.el.addCls('dropOK');
  194.                 }
  195.                 else {
  196.                     // Remove the invitation
  197.                     this.onDragOut();
  198.                 }
  199.             },
  200.             // Only called when element is dragged out of a dropzone with the same ddgroup
  201.             onDragOut : function(evtObj, targetElId) {
  202.                 this.el.removeCls('dropOK');
  203.             }
  204.         };

  205.         // Configure the cars to be draggable
  206.         var carElements = Ext.get('cars').select('div');
  207.         Ext.each(carElements.elements, function(el) {
  208.             var dd = Ext.create('Ext.dd.DD', el, 'carsDDGroup', {
  209.                 isTarget : false
  210.             });
  211.             //Apply the overrides object to the newly created instance of DD
  212.             Ext.apply(dd, overrides);
  213.         });

  214.         var truckElements = Ext.get('trucks').select('div');
  215.         Ext.each(truckElements.elements, function(el) {
  216.             var dd = Ext.create('Ext.dd.DD', el, 'trucksDDGroup', {
  217.                 isTarget : false
  218.             });
  219.             Ext.apply(dd, overrides);
  220.         });

  221.       /* var rentedElements = Ext.get('rented').select('div');
  222.         Ext.each(rentedElements.elements, function(el) {
  223.             var dd = Ext.create('Ext.dd.DD', el, 'trucksDDGroup', {
  224.                 isTarget : false
  225.             });
  226.             Ext.apply(dd, overrides);
  227.         });*/

  228.         // Instantiate instances of Ext.dd.DDTarget for the cars and trucks container
  229.         var carsDDTarget = Ext.create('Ext.dd.DDTarget', 'cars','carsDDGroup');
  230.         var trucksDDTarget = Ext.create('Ext.dd.DDTarget', 'trucks', 'trucksDDGroup');

  231. // Instantiate instnaces of DDTarget for the rented and repair drop target elements
  232.         var rentedDDTarget = Ext.create('Ext.dd.DDTarget', 'rented', 'carsDDGroup');
  233.         var repairDDTarget = Ext.create('Ext.dd.DDTarget', 'repair', 'carsDDGroup');

  234. // Ensure that the rented and repair DDTargets will participate in the trucksDDGroup
  235.         rentedDDTarget.addToGroup('trucksDDGroup');
  236.         repairDDTarget.addToGroup('trucksDDGroup');
  237.     });
  238. </script>


  239. </body>
  240. </html>

阅读(132) | 评论(0) | 转发(0) |
0

上一篇:批量重命名 shell

下一篇:图标收集

给主人留下些什么吧!~~