The path to dojo: How to Use dojo to achieve drag and drop Effects

Source: Internet
Author: User

Now all the sites using Ajax technology have implemented the drag and drop effects, and the dojo framework can also be easily implemented. Compared with other frameworks, Code Less, and better browser compatibility.

The following figure shows the effect of the home page of the 51ajax.com website. Each module can be dragged as needed:

How to implement it? The procedure is as follows. For simplicity, a demo page of drag and drop is created:


The procedure is as follows:
1.html
To implement drag, you must first have a container, and secondly have the elements that can be dragged. Here, we set three divs as containers, whose IDs are container1, container2, and container3. Each container has a div as a drag element, and their class is divdrag.
2. JavaScript code
First, add the following code to the header. JS references, and then register the elements whose class is divdrag as Dojo. DND. the htmldragsource object registers container1, container2, and container3 as three containers, and the drag elements in the specified container can be dragged to the container. The preceding events are encapsulated into a function, add to window. onload event.

To download the complete dojo framework, click here to download: http://download.dojotoolkit.org/release-0.3.1/dojo-0.3.1-ajax.zip.Copy codeThe Code is as follows: // reference the following two dojo packages
Dojo. Require ("dojo. Style ");
Dojo. Require ("dojo. DND .*");

Function Init (){
// Use classname to retrieve the element List and register it as Dojo. DND. htmldragsour
VaR arr=dojo.html. getelementsbyclass ('divdrag ')
For (VAR I = 0; I <arr. length; I ++ ){
VaR parentdiv = arr [I]. parentnode. ID
New dojo. DND. htmldragsource (ARR [I], parentdiv );
}
// Define the container
New dojo. DND. htmldroptarget ("container1", ["container1", "container2", "container3"]);
New dojo. DND. htmldroptarget ("container2", ["container1", "container2", "container3"]);
New dojo. DND. htmldroptarget ("container3", ["container1", "container2", "container3"]);
}

// Add to window. onload event
Window. onload = function () {Init ();}

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.