简体   繁体   English

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

[英]No mousewheel events on Surface Pro 3 with IE11?

It appears that IE11 on Windows 8.1 doesn't send mousewheel events from multitouch scrolling on precision touchpads, like the one on the Type Cover for the new Surface Pro 3. Is there some alternative event I could listen to? 看来Windows 8.1上的IE11不会发送来自精密触摸板上的多点触摸滚动的鼠标滚轮事件,就像新Surface Pro 3的Type Cover上的鼠标滚轮事件一样。我可以听其他替代事件吗? The actual scroll event won't work, as I'm emulating a scrolling area in my canvas application by capturing inputs. 实际的滚动事件将不起作用,因为我正在通过捕获输入来模拟画布应用程序中的滚动区域。

This a bug. 这是一个错误。 There is no work-around until it's fixed. 在解决之前,没有解决方法。 I can confirm it works properly with 2-finger scrolling on Synaptics touchpads and mouse wheels, but not precision touchpads (like in the Surface Type Cover 3, or 4, or the Surface Book). 我可以确认它可以在Synaptics触摸板和鼠标轮上进行两指滚动,但不能在精密触摸板上(例如Surface Type Cover 3或4,或Surface Book)上正常工作。 This is only a problem for Microsoft Edge & Internet Explorer. 这仅是Microsoft Edge&Internet Explorer的问题。 Chrome and Firefox both treat precision touchpad 2-finger scrolling exactly the same as any other touchpad's 2-finger scrolling. Chrome和Firefox都将精确触摸板2指滚动与其他任何触摸板的2指滚动完全一样。

Here is a jsfiddle of the code below to test/verify: 是下面用于测试/验证的代码的jsfiddle:

JS: JS:

(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: HTML:

<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: CSS:

.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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM