Download the X Distribution File.
xEnableDrag(ele[, fnDragStart[, fnDrag[, fnDragEnd]]])
// xEnableDrag r8, Copyright 2002-2007 Michael Foster (Cross-Browser.com) // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL function xEnableDrag(id,fS,fD,fE) { var mx = 0, my = 0, el = xGetElementById(id); if (el) { el.xDragEnabled = true; xAddEventListener(el, 'mousedown', dragStart, false); } // Private Functions function dragStart(e) { if (el.xDragEnabled) { var ev = new xEvent(e); xPreventDefault(e); mx = ev.pageX; my = ev.pageY; xAddEventListener(document, 'mousemove', drag, false); xAddEventListener(document, 'mouseup', dragEnd, false); if (fS) { fS(el, ev.pageX, ev.pageY, ev); } } } function drag(e) { var ev, dx, dy; xPreventDefault(e); ev = new xEvent(e); dx = ev.pageX - mx; dy = ev.pageY - my; mx = ev.pageX; my = ev.pageY; if (fD) { fD(el, dx, dy, ev); } else { xMoveTo(el, xLeft(el) + dx, xTop(el) + dy); } } function dragEnd(e) { var ev = new xEvent(e); xPreventDefault(e); xRemoveEventListener(document, 'mouseup', dragEnd, false); xRemoveEventListener(document, 'mousemove', drag, false); if (fE) { fE(el, ev.pageX, ev.pageY, ev); } if (xEnableDrag.drop) { xEnableDrag.drop(el, ev); } } } xEnableDrag.drops = []; // static property
xGetElementById, xAddEventListener, xRemoveEventListener, xEvent, xMoveTo, xPreventDefault, xLeft, xTop
xfenster - xFenster demos.
drag4.html - A test page for xDragInFence, xEnableDrag and xEnableDrop.
By your use of X and/or CBE and/or any Javascript from this site you consent to the GNU LGPL - please read it. If you have any questions about the license, read the FAQ and/or come to the forums.
Forum support is available at the X Library Support Forums.
Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.
If you are using X, XC or anything from this site, show off your work by posting a link in the X Showcase forum.