zpagra
09-08-2002, 08:55 PM
This is the code for a mouse following script.
I've tried loads of things, but it won't work:
<DIV ID=d STYLE="POSITION: absolute; WIDTH: 30px; HEIGHT: 30px; BACKGROUND-COLOR: red;"></DIV>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!-- HIDE --
var go;
var mx;
var my;
if(document.all){
document.onMouseMove = init;
}
function init(){
var ex = event.clientX;
var ey = event.clientY;
var dl = parseInt(document.d.style.posleft);
var dt = parseInt(document.d.style.postop);
var dx = Math.round((ex - dl) / 20);
var dy = Math.round((ey - dt) / 20);
var mx = dl + dx;
var my = dt + dy;
go = window.setInterval("move()", "50");
}
function move(){
document.d.style.posleft = mx+ "px";
document.d.style.postop = my+ "px";
}
// -- HIDE -->
</SCRIPT>
I just want this to WORK! But it won't.
The red div block should just move to the mouse position and take 1 second to do it - faster movement for longer distances.
I'm using IE5, but would like it to work in IE4.
Any Suggestions?
I've tried loads of things, but it won't work:
<DIV ID=d STYLE="POSITION: absolute; WIDTH: 30px; HEIGHT: 30px; BACKGROUND-COLOR: red;"></DIV>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!-- HIDE --
var go;
var mx;
var my;
if(document.all){
document.onMouseMove = init;
}
function init(){
var ex = event.clientX;
var ey = event.clientY;
var dl = parseInt(document.d.style.posleft);
var dt = parseInt(document.d.style.postop);
var dx = Math.round((ex - dl) / 20);
var dy = Math.round((ey - dt) / 20);
var mx = dl + dx;
var my = dt + dy;
go = window.setInterval("move()", "50");
}
function move(){
document.d.style.posleft = mx+ "px";
document.d.style.postop = my+ "px";
}
// -- HIDE -->
</SCRIPT>
I just want this to WORK! But it won't.
The red div block should just move to the mouse position and take 1 second to do it - faster movement for longer distances.
I'm using IE5, but would like it to work in IE4.
Any Suggestions?