把
ev.pageX 换成 e.originalEvent.targetTouches[0].pageX;
例子:
var
start_x, start_y, end_x, end_y, move_num;
var
client_height = $(window).height();
$(
"#containner div"
).on(
"touchstart"
,
function
(e) {
start_x = e.originalEvent.targetTouches[0].clientX;
start_y = e.originalEvent.targetTouches[0].clientY;
console.log(start_x);
console.log(start_y);
});
$(
"#containner div"
).on(
"touchmove"
,
function
(e) {
$(
this
).removeClass(
"slow_action"
);
end_x = e.originalEvent.targetTouches[0].clientX;
end_y = e.originalEvent.targetTouches[0].clientY;
move_num = (end_y - start_y).toFixed(2);
console.log(move_num);
var
tf_num =
"translateY("
+ move_num +
"px)"
;
$(
this
).css(
"-webkit-transform"
, tf_num);
});
$(
"#containner div"
).on(
"touchend"
,
function
() {
$(
this
).addClass(
"slow_action"
);
if
(move_num < -(client_height / 2)) {
$(
this
).css({
"-webkit-transform"
:
"translateY(-900px)"
,
});
}
else
if
(move_num > 0) {
$(
this
).css({
"-webkit-transform"
:
"translateY(0px)"
,
});
}
else
{
$(
this
).css({
"-webkit-transform"
:
"translateY(0px)"
,
});
}
});