最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if mouse is down on a mouseout event- jQuery - Stack Overflow

programmeradmin3浏览0评论

I want to know if a user stops pressing a button. So I capture the $button.mouseup(...) and $button.mouseout(...) events. However, I want the mouseout event to only matter when the user is still pressing the mouse- Otherwise, it will fire whenever the user passes over the button.

Any ideas?

I want to know if a user stops pressing a button. So I capture the $button.mouseup(...) and $button.mouseout(...) events. However, I want the mouseout event to only matter when the user is still pressing the mouse- Otherwise, it will fire whenever the user passes over the button.

Any ideas?

Share Improve this question asked May 17, 2011 at 16:53 YarinYarin 184k155 gold badges410 silver badges524 bronze badges 1
  • You can just set a global variable to true on mousedown and get that value on mouseout. – pimvdb Commented May 17, 2011 at 16:55
Add a ment  | 

2 Answers 2

Reset to default 8

Check e.which, which indicates the pressed button.

A quick and dirty method would be to use globals (or closures; some way of giving both the mouseup and the mouseout functions access to the same variable):

var mouseIsUp = true,
    onMouseUp = function () {
        mouseIsUp = true;
        // ...
    },
    onMouseDown = function () {
        mouseIsUp = false;
    },
    onMouseOut = function () {
        if (!mouseIsUp) {
            // ...
        }
    };
发布评论

评论列表(0)

  1. 暂无评论