首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用IE11的Surface Pro 3上没有鼠标滚轮事件?

使用IE11的Surface Pro 3上没有鼠标滚轮事件?
EN

Stack Overflow用户
提问于 2014-08-28 23:36:59
回答 1查看 1.3K关注 0票数 1

Windows8.1上的IE11似乎不会发送精确触摸板上多点触控滚动的鼠标滚轮事件,就像新的Surface Pro3的Type Cover上的事件一样。有什么替代事件可以让我收听吗?实际的scroll事件将不起作用,因为我正在通过捕获输入来模拟canvas应用程序中的滚动区域。

EN

回答 1

Stack Overflow用户

发布于 2016-01-19 06:35:40

这是个bug。在它被修复之前没有变通的办法。我可以确认它在Synaptics触摸板和鼠标滚轮上的两指滚动功能正常,但不能在精密触摸板上正常工作(就像Surface Type Cover 3、Surface Type Cover 4或Surface Book那样)。这只是Microsoft Edge和Internet Explorer的问题。Chrome和Firefox对精密触摸板两指滚动的处理方式与其他触摸板的两指滚动完全相同。

Here是以下代码的jsfiddle,用于测试/验证:

JS:

代码语言:javascript
运行
复制
(function($) {
  var $bg = $('.bg'),
    $log = $('.log'),
    xPos = 0;

  // Define wheel event handler:
  function onWheelEvent(e) {
    // Prevent default behavior of scrolling the web page:
    e.preventDefault();
    e.stopPropagation();

    // Determin the wheel's vertical scroll delta:
    var wheelDeltaY = 0;
    if ('deltaY' in e) {
      if (e.deltaMode === 1) {
        wheelDeltaY = ((Math.abs(e.deltaY) < 6) ? e.deltaY * -2 : -e.deltaY) * 20;
      } else {
        wheelDeltaY = -e.deltaY;
      }
    } else if ('wheelDeltaY' in e) {
      wheelDeltaY = e.wheelDeltaY / 120 * 20;
    } else if ('wheelDelta' in e) {
      wheelDeltaY = e.wheelDelta / 120 * 20;
    } else if ('detail' in e) {
      wheelDeltaY = -e.detail / 3 * 20;
    } else {
      $log.append('<p>unable to determine delta</p>');
    }
    xPos = xPos + Math.round(wheelDeltaY);
    $bg.css('background-position', xPos + 'px 0px');
    $log.append('<p>' + e.type + ' event scrolled by ' + wheelDeltaY + 'px. New X position: ' + xPos + '</p>');
    $log.scrollTop($log[0].scrollHeight);
  };
  // Capture wheel events for all browsers 
  //   (I'm not using jQuery's event subscription 
  //    model to show it's not a jQuery problem):
  $bg[0].addEventListener('wheel', onWheelEvent, false);
  $bg[0].addEventListener('mousewheel', onWheelEvent, false);
  $bg[0].addEventListener('DOMMouseScroll', onWheelEvent, false);
})($);

HTML:

代码语言:javascript
运行
复制
<div class="tall">
  <!-- Force browser to show scroll bars -->
  <div class="bg">
    <!--BG image we'll move horizontally -->
    <div class="log">
      <!--Contain the event log-->
      <h3>Scroll with mouse wheel or 2-finger scrolling here</h3>
      <p>
        Expected behavior: The background image (which is large and may take a minute to load) should shift horizontally when scrolling over the image, even though the page is tall enough to have a browser-created vertical scrollbar.
      </p>
      <p>
        If you scroll the mouse over this image, and the page scrolls vertically (and this text isn't replaced with an event log), it means the event was not captured.
      </p>
    </div>
  </div>
</div>

CSS:

代码语言:javascript
运行
复制
.tall {
  height: 2000px;
}

.bg {
  width: 100%;
  height: 300px;
  background-image: url(http://i.imgur.com/DP6K9D8.gif);
  background-position: 0px 0px;
  background-repeat: repeat;
  background-repeat-x: repeat;
  background-repeat-y: no-repeat;
  background-size: contain;
  position: relative;
}

.log {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40%;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.85);
  color: #555;
  max-height: 260px;
  overflow: hidden;
  font-size: 0.7em;
  font-family: arial, sans-serif;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25552748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档