Easy Learning jquery Plugin Easyui Easyui Implementation drag basic Operation _jquery

Source: Internet
Author: User

This tutorial shows you how to make HTML elements drag, in this case, we'll create three DIV elements and then enable their drag and drop.

First, we create three <div> elements:

<div id= "dd1" class= "Dd-demo" ></div>
<div id= "DD2" class= "Dd-demo" ></div>
<div Id= "DD3" class= "Dd-demo" ></div>

For the first >div< element, we have the default value to drag.
$ (' #dd1 '). draggable ();
For the second <div> element, we create a clone (clone) of the original element's proxy (proxy) so that it can be dragged.

$ (' #dd2 '). Draggable ({
 proxy: ' Clone '
});

For the third <div> element, we make it possible to drag by creating a custom proxy (proxy).

$ (' #dd3 '). Draggable ({
 proxy:function (source) {
 var p = $ (' <div class= ' proxy ' >proxy</div> ');
 P.appendto (' body ');
 return p;
 }
});

Here for you to share a simple example of the school curriculum, Welcome to learn:

We'll create two tables: Show the school account on the left and show the timeline on the right. You can drag the school account and place it on the timesheet cell. The school subject is a <div class= "item" > element, the Timesheet cell is a <td class= "drop" > element.

Show school Subjects

<div class= "Left" >
 <table>
 <tr>
  <td><div class= "Item" >english</div ></td>
 </tr>
 <tr>
  <td><div class= "Item" >SCIENCE</DIV></TD >
 </tr>
 <!--other subjects-->
 </table>
</div>

Show timesheet

<div class= "Right" >
 <table>
 <tr>
  <td class= "blank" ></td>
  <td class= "title" >Monday</td>
  <td class= "title" >Tuesday</td>
  <td class= "title" > wednesday</td>
  <td class= "title" >Thursday</td>
  <td class= "title" >friday</td >
 </tr>
 <tr>
  <td class= "Time" >08:00</td>
  <td class= "Drop" > </td>
  <td class= "Drop" ></td>
  <td class= "Drop" ></td>
  <td class= " Drop "></td>
  <td class=" Drop "></td>
 </tr>
 <!--other cells-->
 </table>
</div>

Drag the school account on the left

$ ('. Left. Item '). draggable ({
 revert:true,
 proxy: ' Clone '
});


Place school subjects on the timesheet cell

$ ('. Right Td.drop '). Droppable ({
 ondragenter:function () {
 $ (a). addclass (' over ');
 },
 Ondragleave:function () {
 $ (this). Removeclass ("over");
 },
 ondrop:function (e,source) {
 $ (this). Removeclass (' over ');
 if ($ (source). Hasclass (' assigned ')) {
  $ (this). append (source);
 } else {
  var c = $ (source). Clone (). AddClass (' assigned ');
  $ (this). Empty (). append (c);
  C.draggable ({
  revert:true
  });}}
);

As you can see in the above code, the OnDrop callback function is invoked when the user drags the school account on the left and places it in the timesheet cell. We clone the source element dragged from the left and attach it to the timesheet cell. When you drag a school account from a cell in your timesheet to another cell, simply move it.

The above is to show you how to use jquery Easyui to create a school curriculum, I hope to help everyone's study, we will like, and continue to focus on the next article of the small series.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.