Skip to content

Commit

Permalink
Merge pull request #3 from patricknelson/issue-90-add-touch-compat
Browse files Browse the repository at this point in the history
Feature stephband#90: Adding touch compatibility (new event listeners).
  • Loading branch information
phirschybar authored Jan 7, 2017
2 parents 36f695c + 7ff643d commit 34dac15
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions js/jquery.parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit 34dac15

Please sign in to comment.