YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Drag & Drop: Using a Proxy Element

# Drag & 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>

## Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

### YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### Drag & Drop Examples:

### More Drag & Drop Resources:

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

Copyright © 2010 Yahoo! Inc. All rights reserved.

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