[thelist] detect held-down mouse button
RLivsey
R.Livsey at cache-22.co.uk
Tue Aug 19 06:35:10 CDT 2003
shortestpath wrote:
> is there a way to detect a held-down button, -while-
> the mouse is moving?
> thanks in advance,
> -alex
Paste the following into a new html document.
// -------- Start ----------- //
<html>
<head>
<title>mouse test</title>
<script>
var isDown = false;
function mup()
{
isDown = false;
setText("mouse up");
}
function mdown()
{
isDown = true;
setText("mouse down");
}
function mmove()
{
setText((isDown) ? "move while down" : "move while up");
}
function setText(txt)
{
document.moveTestForm.status.value = txt;
}
</script>
</head>
<body onmouseup="mup()" onmousedown="mdown()" onmousemove="mmove()">
<form name="moveTestForm">
<input type="test" name="status" />
</form>
</body>
</html>
// -------- End ----------- //
so basically on mouse down, set a variable (here called isDown) to true.
On mouse up, set it to false.
When the mouse moves check this var and you can tell if the mouse is
clicked while you are moving the mouse.
hth
--
R.Livsey
Incutio Web Developer
[ PHP | Perl | Java | C# ]
www.cache-22.co.uk
www.incutio.com
More information about the thelist
mailing list