For the last three days I have been working on developing a view panel that will display the users site stats and there sites info on one of my site. I plan to use a absolute div with a title bar that is the handle for the drag and drop control. My problem is that when I click the title bar it does not drag the div right like the div. I have tried at least 12 ways to drag and drop and all of them failed to keep the position of the mouse when I moved the mouse. My curreent version of the drag and drop is really messed up. I was wondering if someone can help me fix my code so when I click the title bar of the div it will drag normally with the mouse?
here is my current drag and drop javascript code:
var x;
var y;
var drag = false;
elm = document.getElementById('view_title');
elm.onmousedown = function(e) {
e = e || event;
target = document.getElementById('view');
x = e.clientX;
y = e.clientY;
ox = elm.style.left;
oy = elm.style.top;
drag = true;
document.documentElement.onmousemove = function(e) {
e = e || event;
if(drag == true) {
target.style.left = (ox-e.clientX-x)+'px';
target.style.top = (oy-e.clientY-y)+'px';
}
}
document.documentElement.onmouseup = function(e) {
e = e || event;
drag = false;
}
}
here is my div code:
<div id="view"><div id="view_title">Loading</div><div id="view_content">Please wait....</div></div>
And finally my current CSS:
#view {
width: 400px;
height: 350px;
visibility: hidden;
z-index: 99;
top:100px;
left:100px;
background-image: url(../images/view.gif);
font-style: oblique;
position: absolute;
}
view_title {}
Thanks for your help.