jquery-idlecat
jquery-idlecat copied to clipboard
Touch activity for mobile browsers
Nice work! I forked it and added touchstart detection for mobile browsers.
Hi there... I wanted to detect touchstart too... @rhiller could you kindly tell me which lines you modify to make it work on cellphones?
Thanks... Stay safe
Wow, I completely forgot about that! My (minor) changes in https://github.com/rhiller/jquery-idlecat
--- a/src/jquery.idleCat.js
+++ b/src/jquery.idleCat.js
@@ -131,7 +131,16 @@
jqDocument.one("mousemove", function (event) {
mouseX = event.pageX;
mouseY = event.pageY;
+ // console.log("mouse x: " + mouseX + " y: " + mouseY);
});
+
+ jqDocument.one("touchstart", function (event) {
+ var touchobj = event.originalEvent.changedTouches[0];
+ mouseX = parseInt(touchobj.pageX);
+ mouseY = parseInt(touchobj.pageY);
+ // console.log("touch x: " + mouseX + " y: " + mouseY);
+ });
+
//console.log(mouseX, mouseY);
var movement = (mouseX != oldMouseX) || (mouseY != oldMouseY);
Worked like a charm!!! Thanks so much!!!
Now, my dear friend... I would like to share the keyboard detection snippet... which I just figured out... Thanks so much!
jqDocument.one("keypress", function (event) { mouseX = event.which; mouseY = event.which; console.log("key pressed: " + mouseX); });