May 12, 2024, 02:51:40 PMLatest Member: Nicholesycle
BoutCheetah » Forum » Other » Off Topic » Need a tad of JS help.

Need a tad of JS help.

Started by daluzman123, February 19, 2013, 08:54:01 AM

Previous topic - Next topic

daluzman123

script>
document.onmousemove = fxy; // when mouse moves call function "xy"

var st = new Date().getTime(), // start time
w = screen.width, // get the width (my website is a center-layout so width/2 will give me the center of the page wich will make it possible to show the replay from different window sizes)
x = 0, // x position of mouse
y = 0, // y position of mouse
a = new Array(); // store mouse movement


function fxy(e) {

var ex = e.pageX,
ey = e.pageY; // since they will be used more than once below I put them in a variable

if (ex > x+30 || ex < x-30 || ey > y+30 || ey < y-30){ // I don't need to log every pixel since it will return a huge string, 30 px in difference is enough


// make the numbers smaller for the string (approximately is enough for this application), they will later be multiplied by 10
x = Math.round(ex/10);
y = Math.round(ey/10);

// get the curent time for the position to be able to record it later (start time - time now)
var t = new Date().getTime() - st;



// array that will be sent to PHP to create a replay of the mouse movement (a image will move with the same cordinates)
// x-position , y-position, curent time on page
a.push(x + "," + y + "," + t);



// only to show
document.Show.onlyforstackoverflow.value = a;

// to be able to se difference in pixels later in if (ex > x+30 || ex < x-30 || ey > y+30 || ey < y-30)
x = ex;
y = ey;

} // end if
} //end function

</script>


This is a Record mouse movement with javascript, I was wondering if anyone was able to shrink the Sequences for less usage,
If not, Thanks anyways.

~Johnny

Copyright © ZylonGaming 2009 - 2024
-Terms of Use-