//check hover coords every second
window.setInterval(function () {
if (coordOne === "" && coordTwo === "" && coordThree === "") {
coordOne = hoverMouse.offset();
return;
} else if (coordOne && coordTwo === "" && coordThree === "") {
coordTwo = hoverMouse.offset();
return;
} else if (coordOne && coordTwo && coordThree === "") {
coordThree = hoverMouse.offset();
return;
} else {
//assuming that all three coord var's are filled
var diffOne = Math.abs(coordOne.left - coordTwo.left);
var diffTwo = Math.abs(coordTwo.left - coordThree.left);
var diffThree = Math.abs(coordOne.top - coordTwo.top);
var diffFour = Math.abs(coordTwo.top - coordThree.top);
//if difference is larger than 800px between any states,
//assume busy background, alert user
if (diffOne > 800 || diffTwo > 800 || diffThree > 800 || diffFour > 800) {
alert("The hover coordinates seem to be all over the screen, you may have an error");
}
//reset coord every 3 seconds
coordOne = "";
coordTwo = "";
coordThree = "";
return;
}
}, 1000);
I have a div stored in the hoverMouse variable thanks to jQuery. This div moves around the screen at the user's discretion, however the method we are using to move this div around is one that is prone to some error. Because of this, if the div moves around the screen quickly and randomly, we know that an error is likely taking place and so we alert the user.
The problem is this: it isn't working! Even when it moves around 800+ pixels constantly, no alert pops up. What could be my error in this code? Also, any general suggestions would be appreciated - I am still learning.

New Topic/Question
Reply



MultiQuote




|