2016-11-24 41 views
0

我點擊紅色矩形中的按鈕來顯示窗口。現在,如果想關閉窗口,我只需點擊灰色條的其他部分即可。我想要做的是修改代碼,第二次點擊紅色矩形中的按鈕關閉窗口,但它不起作用。第二次點擊不能隱藏窗口

enter image description here

我已經把HTML和相關文件here

主HTML是chat.html,其中主要的Javascript在於

assets\plugins\emojiarea\jquery.emojiarea.js 

以下是代碼的一部分:

EmojiMenu.prototype.hide = function(callback) { 
    if (this.emojiarea) { 
     this.emojiarea.menu = null; 
     this.emojiarea.$button.removeClass('on'); 
     this.emojiarea = null; 
    } 
    this.visible = false; 
    this.$menu.hide(); 
}; 

EmojiMenu.prototype.show = function(emojiarea) { 
    if (this.emojiarea && this.emojiarea === emojiarea) return; 
    this.emojiarea = emojiarea; 
    this.emojiarea.menu = this; 

    this.reposition(); 
    this.$menu.show(); 
    this.visible = true; 
}; 

我嘗試使用this.visible檢測窗口是否已如果是,打開,然後關閉它,但它不起作用。當我第二次點擊紅色矩形中的按鈕時,是否有可能關閉窗戶?

+0

你可以使用切換() –

+0

你想隱藏它只在按鈕點擊? – a1626

+0

@ a1626是的,第一次點擊顯示,第二次點擊關閉,第三次點擊打開...並在其他地方點擊它不會有任何影響。 – william007

回答

0

所以我通過插件。這段代碼:
$body.on('mouseup', function() { self.hide(); });
是爲什麼你不能使用this.visible來檢查它是否已經打開或沒有打開,因爲每次你點擊按鈕時,這個mouseup都會被有效地隱藏,然後顯示彈出框。
此後的權利:
$button.on('click', function(e) { EmojiMenu.show(self); e.stopPropagation(); });
加入此項:
$button.on('mouseup', function(e) { e.stopPropagation(); });
這將防止從按鈕本身冒泡mouseup事件。
現在,您可以使用「this.visible來檢測窗口是否已打開,如果是,則關閉它。」

相關問題