开发者

In the mousedown event, is it possible to cancel the resulting click event? or pass info to it?

for arcane reasons I need to be able to cancel the click event via the mousedown event.

Briefly; I am creating a context menu in the mousedown event, however, when the user clicks on the page the context menu should disappear.

I am not able to use the mousedown event over the click in that scenario as I want the user to be able to click links inside the menu ( a full click would never travel to the <a> based menu elements ).

If it is any help, jQuery can be applied.

I would like to either be able to prevent the click event from happening from within the initial mousedown, or be开发者_如何学JAVA able to pass information to the click event (via originalEvent or otherwise).

TIA


Seems to be impossible, neither FF nor Opera didnt cancel upcoming click when prevented in mousedown and/or mouseup (as side note: click is dispatched after mouseup if certain conditions met). testcase: http://jsfiddle.net/ksaeU/


I have just had the exact same problem. I fixed my context menu by closing it on mousedown and eating the mousedown event on the menu so that I can still receive clicks on the menu, like so:

$(document).one('mousedown.ct', null, function() { cmenu.hide(); return false; });
cmenu.bind('mousedown', function(e) { e.stopImmediatePropagation(); });

And in the hide() function I unbind the mousedown.ct again, in case it was closed due to a click on an item.


Hey, I think this is what you are trying to do with your code. If not, I apologize, I may have misunderstood the question. I used jQuery to get it done: http://jsfiddle.net/jackrugile/KArRD/

$('a').bind({
    mousedown: function(){
        // Do stuff
    },
    click: function(e){
        e.preventDefault();
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜