我正在开发Chrome扩展程序。我想在当前打开的页面或标签上长按时显示一个弹出窗口。如何检测页面上的文本何时被长按?
答案 0 :(得分:0)
(function() {
// how many milliseconds is a long press?
var longpress = 3000;
// holds the start time
var start;
jQuery( "#pressme" ).on( 'mousedown', function( e ) {
start = new Date().getTime();
} );
jQuery( "#pressme" ).on( 'mouseleave', function( e ) {
start = 0;
} );
jQuery( "#pressme" ).on( 'mouseup', function( e ) {
if ( new Date().getTime() >= ( start + longpress ) ) {
// If you want to get the text of the element, use jQuery's element.text()
alert('long press! You pressed: ' + $(this).text());
} else {
alert('long press! You pressed: ' + $(this).text());
}
} );
}());
虽然这是一个jQuery示例,但这也是可能的(参见Walk&#39的示例)