Enkelt exempel:
<script type="text/javascript">
var elm,
lpos,
tpos,
curL,
curT,
active = false;
document.onmousedown = function(e){
var evt;
if (typeof (evt = window.event) != "undefined" && evt.srcElement == elm){
active = true;
lpos = evt.screenX;
tpos = evt.screenY;
curL = elm.offsetLeft;
curT = elm.offsetTop;
}
else if (typeof (evt = e) != "undefined" && e.target == elm){
active = true;
lpos = evt.pageX;
tpos = evt.pageY;
curL = elm.offsetLeft;
curT = elm.offsetTop;
}
}
document.onmousemove = function(e){
var evt;
if (active && typeof (evt = window.event) != "undefined"){
elm.style.left = curL + (evt.screenX - lpos);
elm.style.top = curT + (evt.screenY - tpos);
}
else if (active && typeof (evt = e) != "undefined"){
elm.style.left = curL + (evt.pageX - lpos) + "px";
elm.style.top = curT + (evt.pageY - tpos) + "px";
}
}
document.onmouseup = function(){ active = false; }
window.onload = function(){ elm = document.getElementById("foo"); }
</script>
<div id="foo" style="position:absolute; width:200px; height:75px; border:1px solid; background:#eee"></div>
:)