【问题标题】:How can I detect click is hold but not moved?如何检测点击被保持但未移动?
【发布时间】:2018-08-03 02:01:18
【问题描述】:

这是我的代码:

doc.on('mousedown', '.qandacontent', function() {
    timeout_id = setTimeout(menu_toggle.bind(this), 1000);
}).bind('mouseup mouseleave', function() {
    clearTimeout(timeout_id);
});

如果您单击元素 .qandacontent 并按住 1 秒钟,这将显示一个弹出窗口。现在我想让它仅在单击按住时没有选择(标记)文本时才起作用。知道我该怎么做吗?

【问题讨论】:

  • 如果可以的话,提供一个可运行的 sn-p 会很有帮助。或者添加 html,以便回复的人可以提供与您的问题陈述非常匹配的 sn-p

标签: javascript jquery


【解决方案1】:

您可以检查是否有选定的文本,如果有,它在哪里:

if ($(window.getSelection().anchorNode).attr('id') === 'something') { ... }

见:

【讨论】:

    猜你喜欢
    • 2012-09-08
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多