简体   繁体   中英

How can I detect click is hold but not moved?

Here is my code:

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

This will show a pop up if you click on element .qandacontent and hold it for 1 sec. Now I want to make it working only if no text is selected (marked) while click-holding. Any idea how can I do that?

You could check if there is selected text, and if so, where it is :

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

See:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM