ConfusedOfLife
08-28-2002, 10:35 AM
I wrote this program to simulate a simple window, I mean a window that you can move if you hold press the mouse button on the title of the window, here's the program :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="Pos" style="position : absolute; top : 10px; left : 50px; width : 100px; height : 100px; background-color : red;">
<div id="Title" style="position : relative; cursor : default; background-color :blue; width : 100px; height : 25px">
<span>Our Title</span>
</div>
<span id="cont">This is just a test.</span>
</div>
<script>
mx = 0; my = 0;
function trackmouse(evt)
{
mx = event.clientX + document.body.scrollLeft;
my = event.clientY + document.body.scrollTop;
}
function doit()
{
trackmouse();
currTop = parseInt(document.getElementById("Pos").style.pixelTop);
currLeft = parseInt(document.getElementById("Pos").style.pixelLeft);
capX1 = mx - currLeft - 2;
capY1 = my - currTop - 2;
document.getElementById("Pos").style.pixelTop = currTop + capY1 - capY0;
document.getElementById("Pos").style.pixelLeft = currLeft + capX1 - capX0;
}
document.getElementById("Title").onmousedown = function()
{
trackmouse();
capX0 = mx - document.getElementById("Pos").style.pixelLeft - 2;
capY0 = my- document.getElementById("Pos").style.pixelTop - 2;
document.getElementById("Title").onmousemove = function()
{
doit();
}
}
document.getElementById("Title").onmouseup = document.getElementById("Title").onmouseout =
function() { };
</script>
</body>
</html>
But there are several problems with my program:
1- It seems that the mouse moves faster than my layer, because most of the times the layer falls behind the mouse pointer.
2- Even though I tried to stop moving the layer after mouseup, I mean when the user leaves the mouse button, it doesn't work properly.
3- By going on the title, and trying to drag the simulated window, the text of the title get's highlighted too, that I couldn't do anything for that.
I would appreciate it if anyone can fix these bugs and also I like to hear all the suggestions for improving my program.
Many thanx in advance
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="Pos" style="position : absolute; top : 10px; left : 50px; width : 100px; height : 100px; background-color : red;">
<div id="Title" style="position : relative; cursor : default; background-color :blue; width : 100px; height : 25px">
<span>Our Title</span>
</div>
<span id="cont">This is just a test.</span>
</div>
<script>
mx = 0; my = 0;
function trackmouse(evt)
{
mx = event.clientX + document.body.scrollLeft;
my = event.clientY + document.body.scrollTop;
}
function doit()
{
trackmouse();
currTop = parseInt(document.getElementById("Pos").style.pixelTop);
currLeft = parseInt(document.getElementById("Pos").style.pixelLeft);
capX1 = mx - currLeft - 2;
capY1 = my - currTop - 2;
document.getElementById("Pos").style.pixelTop = currTop + capY1 - capY0;
document.getElementById("Pos").style.pixelLeft = currLeft + capX1 - capX0;
}
document.getElementById("Title").onmousedown = function()
{
trackmouse();
capX0 = mx - document.getElementById("Pos").style.pixelLeft - 2;
capY0 = my- document.getElementById("Pos").style.pixelTop - 2;
document.getElementById("Title").onmousemove = function()
{
doit();
}
}
document.getElementById("Title").onmouseup = document.getElementById("Title").onmouseout =
function() { };
</script>
</body>
</html>
But there are several problems with my program:
1- It seems that the mouse moves faster than my layer, because most of the times the layer falls behind the mouse pointer.
2- Even though I tried to stop moving the layer after mouseup, I mean when the user leaves the mouse button, it doesn't work properly.
3- By going on the title, and trying to drag the simulated window, the text of the title get's highlighted too, that I couldn't do anything for that.
I would appreciate it if anyone can fix these bugs and also I like to hear all the suggestions for improving my program.
Many thanx in advance