【问题标题】:mouse move event conflict with touch event in IE11 of window 8.1pc鼠标移动事件与窗口 8.1pc 的 IE11 中的触摸事件冲突
【发布时间】:2014-07-03 14:12:51
【问题描述】:

我为window 8.1 tablet 和window 8.1 pc 的IE11 创建了一个网页。在这个页面中,滚动可以通过javascript来处理。

对于 html,

<div style="overflow:hidden; -webkit-overflow-scrolling:touch; -ms-touch-action: none; touch-action: none; height: 100px" id="scrolledDiv">
   <table id="ContentTable" cellpadding="0" cellspacing="0">
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
      <tr>
          <td>
            aaa
          </td>
      </tr>
   </table>
<div>

在 JavaScript 中,

var startY;
if (window.navigator.msPointerEnabled) {
   document.getElementById('scrolledDiv').addEventListener("MSPointerDown", 
     function(e){
       startY = e.pageY;
       e.preventDefault();
      }, false);

   document.getElementById('scrolledDiv').addEventListener("MSPointerMove", function(e){
        var touches = e.pageY;
        // override the touch event’s normal functionality
        e.preventDefault();

        // y-axis
        var touchMovedY = startY - touches;
        startY = touches; // reset startY for the next call
        document.getElementById('scrolledDiv').scrollTop = document.getElementById('scrolledDiv').scrollTop + touchMovedY;
      }, false);
}

当用户进行触摸事件时,滚动在窗口平板 8.1 的 IE 11 中运行良好。但是当用户在窗口 8.1 pc 的 IE 11 中移动鼠标时,它就像触摸事件一样工作。我不想在窗口 8.1 pc 的 IE 11 中的鼠标移动事件中获得滚动过程。我怎样才能避免这种情况?谢谢大家。

【问题讨论】:

    标签: javascript touch internet-explorer-11 mousemove mousedown


    【解决方案1】:

    现在,我找到了解决方案。指针事件对象(e) 中有pointerType 属性。我将以下 sn-p 包装到我的代码中。

    if (e.pointerType == 'touch'){
      // your touch event code
    }
    

    指针类型支持触摸、鼠标和笔。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 2021-02-10
      • 2017-08-20
      相关资源
      最近更新 更多