From 7ff643dfe5c7cd68c01f7c5e0e20f3f24ed1fdca Mon Sep 17 00:00:00 2001 From: Patrick Nelson Date: Wed, 11 May 2016 16:05:14 -0700 Subject: [PATCH] Feature #90: Adding touch compatibility (new event listeners). --- js/jquery.parallax.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/js/jquery.parallax.js b/js/jquery.parallax.js index fa15d8f..9083295 100644 --- a/js/jquery.parallax.js +++ b/js/jquery.parallax.js @@ -513,7 +513,23 @@ // Pick up and store mouse position on document: IE does not register // mousemove on window. - doc.on('mousemove.parallax', function(e){ - mouse = [e.pageX, e.pageY]; + doc.on('mousemove.parallax touchstart.parallax touchmove.parallax touchend.parallax', function(e){ + var x, y; + if (e.pageX) { + x = e.pageX; + y = e.pageY; + + } else if (e.originalEvent.touches) { + var touches = e.originalEvent.touches; + if (touches.length == 0) return; + + x = touches[0].pageX; + y = touches[0].pageY; + + } else { + // No coords, nothing to do. + return; + } + mouse = [x, y]; }); }(jQuery)); \ No newline at end of file