gpt4 book ai didi

Hammer.js - Panstart 事件多次触发

转载 作者:行者123 更新时间:2023-12-03 09:20:45 25 4
gpt4 key购买 nike

为什么我的 panstart 事件触发频率与 pan 事件触发频率相同? panstart 不是应该每个手势只触发一次吗?

var myElement = document.getElementById('myElement');
var myResult = document.getElementById('myResult');

// create a simple instance
var mc = new Hammer(myElement);

// setup pan gesture support
mc.get('pan').set({ event: 'panstart', direction: Hammer.DIRECTION_ALL });

// listen to events...
var timesFired = 0;
mc.on("panstart", function(ev) {
timesFired++;
myElement.textContent = ev.type;
myResult.textContent = '# events fired: ' + timesFired;
});
#myElement {
background: silver;
height: 100px;
text-align: center;
font: 50px/100px Helvetica, Arial, sans-serif;
}

#myResult {
text-align: center;
font: 50px/70px Helvetica, Arial, sans-serif;
}
<script src="https://hammerjs.github.io/dist/hammer.js"></script>

<div id="myElement">(pan here)</div>
<div id="myResult"></div>

最佳答案

当你写下这个

mc.get('pan').set({ event: 'panstart', direction: Hammer.DIRECTION_ALL });

您是说,当检测到平移时,应该触发名为 panstart 的事件。这就是为什么你会得到这么多 panstart。

修改:

mc.get('pan').set({ **enable: true**, direction: Hammer.DIRECTION_ALL });

// listen to events...
var timesFired = 0;
mc.on("panstart pan", function(ev) {
timesFired++;
myElement.textContent = ev.type;
myResult.textContent = '# events fired: ' + timesFired;
});

关于Hammer.js - Panstart 事件多次触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31740308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com