iphone的safari touchmove活动无法正常工作

时间:2021-02-15 00:05:29

i am using jquery and touchmove event but the code is not showing anything in #info

我正在使用jquery和touchmove事件,但代码没有在#info中显示任何内容

$('#movieShow').bind('touchmove',function(e){                   
    e.preventDefault();                 
    $('#info').text(e.touches[0].pageX);
});         

2 个解决方案

#1


35  

Try using e.originalEvent.touches:

尝试使用e.originalEvent.touches:

$('#movieShow').bind('touchmove',function(e){
    e.preventDefault();

    var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
    console.log(touch.pageX);
});

I ran into a similar problem when I was playing around with touch events and jquery: http://xavi.co/articles/trouble-with-touch-events-jquery

当我玩触摸事件和jquery时,我遇到了类似的问题:http://xavi.co/articles/trouble-with-touch-events-jquery

#2


1  

It might be as simple as a mis-named DIV id ('#info') but can't tell without seeing everything.

它可能就像一个错误命名的DIV id('#info')一样简单,但是如果没有看到一切就无法分辨。

Try this, and see if you still get no output:

试试这个,看看你是否仍然没有输出:

$('#movieShow').bind('touchmove',function(e){                   
    e.preventDefault();                 
    console.log(e.touches[0].pageX);
});

(You'll need to turn on Debug Console in MobileSafari)

(您需要在MobileSafari中打开调试控制台)

UPDATE

UPDATE

So, from your comment you get an error: 'e.touches' is not an object

因此,从您的评论中您会收到一个错误:'e.touches'不是一个对象

In that case try this (not jQuery specific):

在这种情况下尝试这个(不是特定于jQuery):

document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
document.getElementById('movieShow').addEventListener('touchmove',  function(e){
  console.log(e.touches[0].pageX);
},  false);

#1


35  

Try using e.originalEvent.touches:

尝试使用e.originalEvent.touches:

$('#movieShow').bind('touchmove',function(e){
    e.preventDefault();

    var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
    console.log(touch.pageX);
});

I ran into a similar problem when I was playing around with touch events and jquery: http://xavi.co/articles/trouble-with-touch-events-jquery

当我玩触摸事件和jquery时,我遇到了类似的问题:http://xavi.co/articles/trouble-with-touch-events-jquery

#2


1  

It might be as simple as a mis-named DIV id ('#info') but can't tell without seeing everything.

它可能就像一个错误命名的DIV id('#info')一样简单,但是如果没有看到一切就无法分辨。

Try this, and see if you still get no output:

试试这个,看看你是否仍然没有输出:

$('#movieShow').bind('touchmove',function(e){                   
    e.preventDefault();                 
    console.log(e.touches[0].pageX);
});

(You'll need to turn on Debug Console in MobileSafari)

(您需要在MobileSafari中打开调试控制台)

UPDATE

UPDATE

So, from your comment you get an error: 'e.touches' is not an object

因此,从您的评论中您会收到一个错误:'e.touches'不是一个对象

In that case try this (not jQuery specific):

在这种情况下尝试这个(不是特定于jQuery):

document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
document.getElementById('movieShow').addEventListener('touchmove',  function(e){
  console.log(e.touches[0].pageX);
},  false);