Yahoo! Developer Network Home - Help

YDN Site Search

# YUI Library Examples: Drag & Drop: Drag and Drop using a Proxy Element

# Drag & Drop: Drag and Drop using a Proxy Element

This example demonstrates drag and drop using a proxy element.

View example in new window.

Custom

## Drag and Drop Proxies

The YUI Drag & Drop Utility lets you make HTML elements draggable.

For this example, we will enable drag and drop for the three `<div>` elements. However, instead of dragging the elements around, a proxy element is created and moved instead. Many implmentations can benefit from the use of the proxy element because it avoids positioning complications that can occur when changing the css styles of the source element. Proxy drags also perform better than dragging the element directly.

Create the `demo` elements:

<div id="dd-demo-1" class="dd-demo"></div> <div id="dd-demo-2" class="dd-demo"></div> <div id="dd-demo-3" class="dd-demo"></div> <div id="dd-demo-3-proxy">Custom</div>

Now we create the instances of `YAHOO.util.DDProxy`, passing the element ids or references for our demo elements.

<script type="text/javascript"> (function() { var dd, dd2, dd3; YAHOO.util.Event.onDOMReady(function() { // The first two instances will share a proxy // element, created automatically by the utility. // This element will be resized at drag time so // that it matches the size of the source element. // It is configured by default to have a 2 pixel // grey border. dd = new YAHOO.util.DDProxy("dd-demo-1"); dd2 = new YAHOO.util.DDProxy("dd-demo-2"); // The third instance has a dedicated custom proxy dd3 = new YAHOO.util.DDProxy("dd-demo-3", "default", { // Define a custom proxy element. It will be // created if not already on the page. dragElId: "dd-demo-3-proxy", // When a drag starts, the proxy is normally // resized. Turn this off so we can keep a // fixed sized proxy. resizeFrame: false }); }); })(); </script>

### YUI Logger Output:

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

### Drag & Drop Examples:

- Basic Drag and Drop
- Drag and Drop Handles
- Drag and Drop with the Dragged Element on Top
- Drag and Drop using a Proxy Element
- Using Drag and Drop to Reorder a List
- Drag and Drop Interaction Groups
- Drag and Drop - Resizable Panel
- Drag and Drop - Custom Click Validator

### More Drag & Drop Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2007 Yahoo! Inc. All rights reserved.

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