开发者

Check if mouse is down on a mouseout event- jQuery

开发者 https://www.devze.com 2023-03-06 18:53 出处:网络
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 pressin

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 t开发者_StackOverflow社区he button.

Any ideas?


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

精彩评论

暂无评论...
验证码 换一张
取 消