【发布时间】:2013-09-22 02:00:18
【问题描述】:
当用户单击并按住 chrome 扩展程序中的任何页面时,如何触发功能? 这是我正在使用的,但它不起作用:
manifest.json
{
"manifest_version": 2,
"name": "Harvix extension",
"description": "Shortcut to search on Harvix",
"version": "0.0.1",
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["jquery.js", "core.js"]
}
],
"permissions": [
"tabs", "<all_urls>"
]
}
core.js
var timeout;
function open(text) {
$('#myElement').mousedown(function() {
timeout = setTimeout(null, 1000);
}).bind('mouseup mouseleave', function() {
clearTimeout(timeout);
});
alert('hello');
}
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {code: open(window.getSelection().toString())});
});
【问题讨论】:
-
Trigger Click-and-Hold Event 的可能重复项
-
我认为这个问题是关于 jquery 中的 darg&drop
-
如果你选择不在你的扩展中使用 jQuery,那么同样的方法也适用,但你仍然需要滚动你自己的 Click and Drag 方法,我收集到你的
"js": ["jquery.js", "core.js"]行代码意味着您可以使用 jQuery 库来让您的生活更轻松,不妨使用它 -
我想你误会了我,我希望能够检测单击并按住,而不是单击并拖动
-
对不起,我的评论是说
Hold,而不是Drag。如果您特别想检测保持(没有任何移动),则计算释放前后的 x/y 位置将确保忽略 Click & Drag 事件。