gpt4 book ai didi

javascript - Hammer.JS 桌面文本选择和滑动冲突

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:07:25 34 4
gpt4 key购买 nike

我有一个 Hammer.js 2.06 的工作实现,可以使用水平滑动在页面之间跳转。但是我在桌面上发现有冲突。当用户使用鼠标选择一段文本时,该操作还会触发 Hammer 的滑动事件。

我想允许文本选择的默认浏览器行为,但也使用 Hammer 的滑动手势。有没有办法让两者一起工作?或者我应该禁用鼠标手势支持,因为文本选择功能更为重要,我该怎么做?

delete Hammer.defaults.cssProps.userSelect // as suggested in tips 'n tricks
var myElement = document.getElementById("gestureCanvas"),
nextp = document.getElementById("GotoNextPage"),
prevp = document.getElementById("GotoPrevPage"),
mc = new Hammer(myElement, {
doubletap: false,
pan: false,
press: false,
pinch: false,
rotate: false,
tap: false
});
// gesture event listeners
mc.on("swipeleft swiperight", function(ev) {
if (ev.type === "swipeleft") {
if (Boolean(nextp.disabled) === false) {
nextp.click();
}
} else if (ev.type === "swiperight") {
if (Boolean(prevp.disabled) === false) {
prevp.click();
}
}
});

最佳答案

公认的解决方案对我不起作用,所以我用谷歌搜索,这就是我找到的。

“I can’t select my text anymore!”

Hammer is setting a property to improve the UX of the panning on desktop. Regularly, the desktop browser would select the text while you drag over the page. The user-select css property disables this.

If you care about the text-selection and not so much about the desktop experience, you can simply remove this option from the defaults. Make sure you do this before creating an instance.

delete Hammer.defaults.cssProps.userSelect;

http://hammerjs.github.io/tips/

关于javascript - Hammer.JS 桌面文本选择和滑动冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35142386/

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