2017-10-17 89 views
0

我想在Chrome中製作一個幻燈片效果,但是當我滑動時我總是收到一個錯誤。這是我的代碼:element.changedTouches [0]錯誤未定義。 Chrome bug?

$(function() { 
     $('.table.table-responsive.table-condensed tbody tr').on('touchstart', function (e) { 
      touchsurface.innerHTML = '' 
      var touchobj = e.changedTouches[0] 
      dist = 0 
      startX = touchobj.pageX 
      startY = touchobj.pageY 
      startTime = new Date().getTime() // record time when finger first makes contact with surface 
      e.preventDefault(); 
     }); 
    }, false) 

這是我得到的錯誤:Uncaught TypeError:無法讀取未定義的屬性'0'。這是在線:var touchobj = e.changedTouches [0]

+0

以防萬一,如果你調試jQuery的事件,用'的console.log(E)'比如,它包含了'targetTouches'? – lovethebomb

回答

1

jQuery事件對象沒有changedTouches屬性。

The following properties are also copied to the event object, though some of their values may be undefined depending on the event:

altKey, bubbles, button, buttons, cancelable, char, charCode, clientX, clientY, ctrlKey, currentTarget, data, detail, eventPhase, key, keyCode, metaKey, offsetX, offsetY, originalTarget, pageX, pageY, relatedTarget, screenX, screenY, shiftKey, target, toElement, view, which

https://api.jquery.com/category/events/event-object/

使用

e.originalEvent.changedTouches[0]