thomd/jquery-scroll — Issue #21: Mobile
Author: tsukasa1989
Created: 2012-03-02 11:12:03+00:00
State: open

Hello,

I needed some mobile scrolling and made the following code.

Functions to add:

onTouchStart : function(e){
this.touch = {
start : {
y : e.touches[0].pageY
}
};
},

onTouchMove: function(e){
// calculate new handle position
this.handle.top += (e.touches[0].pageY - this.touch.start.y) * 0.01;

this.setHandlePosition();
this.setContentPosition();

// prevent default scrolling of the entire document if handle is within [min, max]-range
if(this.handle.top > this.props.handlePosition.min && this.handle.top < this.props.handlePosition.max){
e.preventDefault();
}
},

Add the following code to the function appendEvents:

// Touch events
var _this = this;
this.container[0].addEventListener("touchstart", function(e){
e.preventDefault();
_this.onTouchStart(e);
}, false);

this.container[0].addEventListener("touchmove", function(e){
e.preventDefault();
_this.onTouchMove(e);
}, false);

Good luck!

Tsukasa