YUI 3.x Home -

YUI Library Examples: Drag & Drop: Proxy Drag

Drag & Drop: Proxy Drag

This example shows a simple proxy drag interaction that doesn't require a drop interaction.

Drag Me

Setting up the Node

First we need to create an HTML Node to make draggable.

  1. <div id="demo">Drag Me</div>
<div id="demo">Drag Me</div>

Now we give that Node some CSS to make it visible.

  1. #demo {
  2. height: 100px;
  3. width: 100px;
  4. border: 1px solid black;
  5. background-color: #8DD5E7;
  6. cursor: move;
  7. }
#demo {
    height: 100px;
    width: 100px;
    border: 1px solid black;
    background-color: #8DD5E7;
    cursor: move;
}

Setting up the YUI Instance

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

  1. YUI().use('dd-drag', 'dd-proxy');
YUI().use('dd-drag', 'dd-proxy');

Making the Node draggable

Now that we have a YUI instance with the dd-drag and dd-proxy modules, we need to instantiate the Drag instance on this Node and add the DDProxy plugin.

  1. YUI().use('dd-drag', 'dd-proxy', function(Y) {
  2. //Selector of the node to make draggable
  3. var dd = new Y.DD.Drag({
  4. node: '#demo',
  5. }).plug(Y.Plugin.DDProxy); //This config option makes the node a Proxy Drag
  6. });
YUI().use('dd-drag', 'dd-proxy', function(Y) {
    //Selector of the node to make draggable
    var dd = new Y.DD.Drag({
        node: '#demo',
    }).plug(Y.Plugin.DDProxy); //This config option makes the node a Proxy Drag
});

Copyright © 2009 Yahoo! Inc. All rights reserved.

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