jQuery连续mousedown [英] jQuery continuous mousedown

查看:104
本文介绍了jQuery连续mousedown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码片段

$(document).mousedown(function(event) {
    doSomething();
}

我可以捕获 mousedown 活动成功。

我正在尝试执行以下操作:

I am trying to do the following:


  1. 捕获第一个 mousedown 事件

  2. 我想检测用户是否仍然按住鼠标以便我可以做某事否则。


推荐答案

类似

var mouseStillDown = false;

$(document).mousedown(function(event) {
    mouseStillDown = true;
    doSomething();
});

function doSomething() {
    if (!mouseStillDown) { return; } // we could have come back from
                                     // SetInterval and the mouse is no longer down
    // do something

    if (mouseStillDown) { setInterval("doSomething", 100); }
}

$(document).mouseup(function(event) {
    mouseStillDown = false;
});

这篇关于jQuery连续mousedown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆