More About Me...

Welcome to cross-bytes blog, We provide a professional range of IT solutions and services targeted at small, medium and big sized organisations. We're located in Indonesia.

Another Tit-Bit...

Our team of multi disciplined personnel and the dynamic nature of the knowledgebase allows us to provide a complete range of solutions befitting any organisation.

Drad and drop menu

One day, we’ve some project to built web desktop. We want to the menu in desktop can be drag and drop. So I started to search how to image can be drag and drop in javascript. So here’s the script :

first, you can add the script below in your HTML document inside the HEAD tags <head> and </head>

<style>
<!–
.dragme{position:relative;}
–>
</style>
<script language=”JavaScript1.2″>
<!–

var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
if (isdrag)
{
dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
return false;
}
}

function selectmouse(e)
{
var fobj = nn6 ? e.target : event.srcElement;
var topelement = nn6 ? “HTML” : “BODY”;

while (fobj.tagName != topelement && fobj.className != “dragme”)
{
fobj = nn6 ? fobj.parentNode : fobj.parentElement;
}

if (fobj.className==”dragme”)
{
isdrag = true;
dobj = fobj;
tx = parseInt(dobj.style.left+0);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
y = nn6 ? e.clientY : event.clientY;
document.onmousemove=movemouse;
return false;
}
}

document.onmousedown=selectmouse;
document.onmouseup=new Function(”isdrag=false”);

//–>
</script>

Note : which the class “dragme” to whichever image you wish draggable

Leave a Reply

Ad Spot Ad Spot Ad Spot

MYSPONSORS

    website counter
    website counter