开发者

hide on second click

I have a bubble that pops up when you select some text on a document. Now when you select some text, the body开发者_开发技巧 click event fires too. On body event, I have code to hide the bubble that pops up when you select some text. The problem is, I want to show the bubble when the text is selected (even though body event has fired) but I want to hide it when clicked anywhere except inside the bubble.

$('body').live('click', function(e) {
        if($(e.target).parents('.discuss').length == 0) {
            $('.discuss').fadeOut(150);
        }
});

... there is the body event code, now the discuss bubble shows up when some text is selected on the body, the discuss bubble is positioned near the selected text


In the body click handler look at e.target (srcElement in IExplorer). If the target/srcElement is different than the element containing the text you will now that the user has clicked somewhere else in the document and will close the bubble. If the target is the text element itself just return, no need to do anything.


I dont understand clearly by reading your question description.

But as your header title says on "second clik".

flag=0;

Why dont you set a flag value on first click on a hidden field.

(flag=1)

Then on second click check the hidden field value and do what you want. if(flag==1) do it

Show hide or whatever.

Dont forget to reset the value again.


have you tried using mouseup instead of click on the body? that way the bubble will only appear when visitor selected the text and releases their mouse...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜