YUI 3.x Home -

YUI Library Examples: Drag & Drop: Drop Based Coding

Note: This is YUI 3.x. Looking for YUI 2.x?

Drag & Drop: Drop Based Coding

This example shows how to use the Drop Target events to code your application.

Drag #1
Drag #2
Drag #3
Drag #4
Drag #5

Setting up the HTML

First we need to create the HTML for the example.

Now we give the HTML some CSS to make them visible.

Setting up the YUI Instance

Now we need to create our YUI instance and tell it to load the dd-drop and dd-constrain modules.

Making the Nodes draggable

Now that we have a YUI instance with the dd-drop module, we need to instantiate the Drag instance on each Drag Node.

In this example we are using the data config option of the drag to associate data with this Drag instance.

So we have set up an object literal containing information about our drag items.

Now we walk through the nodes and create a drag instance from each of them.

Setting up the Drop Target

Here we set up the Drop Target and assign a listener to it.

Full Example Source

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings