Windows8.1上的IE11似乎不会发送精确触摸板上多点触控滚动的鼠标滚轮事件,就像新的Surface Pro3的Type Cover上的事件一样。有什么替代事件可以让我收听吗?实际的scroll事件将不起作用,因为我正在通过捕获输入来模拟canvas应用程序中的滚动区域。
发布于 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:
(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:
<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:
.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;
}
https://stackoverflow.com/questions/25552748
复制相似问题