1 Replies - 468 Views - Last Post: 02 January 2013 - 04:36 PM

#1 thesixthsense  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 61
  • Joined: 08-January 11

Alerting user on large coord change

Posted 02 January 2013 - 04:15 PM

//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.

Is This A Good Question/Topic? 0
  • +

Replies To: Alerting user on large coord change

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Alerting user on large coord change

Posted 02 January 2013 - 04:36 PM

Hey.

Have you checked out the values using a debugger? Things like Firebug for Firefox, or the Chrome developer tools can be used to place breakpoints, so that you can see exactly what values are being used by your code when a certain line is reached. That would give you a clue why your code isn't working as you expect it to. - I suggest you read this:

Chrome Developer Tools: Breakpoints
Firebug Breakpoints


Also, the return statements you use in that function are kind of redundant. In each case, the next line of code following the return statement would end the function naturally, so there is really no point forcing it to end using return.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1