2013-04-26 81 views
0

我試圖在我的網站上實現jQuery的泡沫彈出,但我完全卡住了。我正在嘗試做以下事情。實現jQuery的泡泡彈出的點擊事件

  1. 如果有人點擊「報告信息」div,彈出的泡泡會顯示與該報告有關。
  2. 我希望能夠改變彈出窗口中的內容,然後單擊提交將該數據發佈到該服務器。
  3. 如果在彈出窗口外單擊一次。我希望它只是關閉。

很簡單的設置,但我拉我的頭髮。如果沒有出現故障,無法關閉彈出窗口。

小提琴http://jsfiddle.net/rECnm/1/

jQueryBubblePopuphttp://www.maxvergelli.com/jquery-bubble-popup

代碼

$(document).ready(function() { 
    $('div.emailReportIcon').CreateBubblePopup({ 
     manageMouseEvents: false 
    }); 
    $('div.emailReportIcon').click(function (event) { 
     var button = $(this); 
     var email = button.attr("data-email"); 
     var message = '<div style="padding:10px;width: 250px;"><p><input type="checkbox"> Email me when new reports are ready.</p>' + '<p>Email Address<br /><input type="text" value="' + email + '"></p>' + '<div >' + '<input type="image" name="submit" value="submit" class="submitButton">' + '</div></div>'; 
     button.ShowBubblePopup({ 
      manageMouseEvents: false, 
      position: 'bottom', 
      align: 'left', 
      tail: { 
       align: 'left' 
      }, 
      innerHtml: message, 
      innerHtmlStyle: { 
       color: '#000', 
       'text-align': 'left' 
      }, 
      themePath: 'http://www.maxvergelli.com/docs/jquery-bubble-popup-examples/images/jquerybubblepopup-themes', 
      alwaysVisible: false, 
      closingDelay: 200, 
      selectable: true 
     }); 
    }); 
}); 
+0

'.HideBubblePopup()'不適合你? – zeroflagL 2013-04-26 22:16:30

+0

然而,我試過,不知道如何實現,如果用戶點擊泡泡彈出。 – KingKongFrog 2013-04-26 22:18:28

回答

2

http://jsfiddle.net/rECnm/9/

var button = false; 
var active = true; 
$(document).ready(function() { 
    $('div.emailReportIcon').CreateBubblePopup({ 
     manageMouseEvents: false 
    }); 
    $('div.emailReportIcon').click(function (event) { 
     resetActiveBubble(); 
     button = $(this); 
     active = true; 
     var email = button.attr("data-email"); 
     var message = '<div style="padding:10px;width: 250px;"><p><input type="checkbox"> Email me when new reports are ready.</p>' + '<p>Email Address<br /><input type="text" value="' + email + '"></p>' + '<div >' + '<input type="image" name="submit" value="submit" class="submitButton">' + '</div></div>'; 
     button.ShowBubblePopup({ 
      manageMouseEvents: false, 
      position: 'bottom', 
      align: 'left', 
      tail: { 
       align: 'left' 
      }, 
      innerHtml: message, 
      innerHtmlStyle: { 
       color: '#000', 
       'text-align': 'left' 
      }, 
      themePath: 'http://www.maxvergelli.com/docs/jquery-bubble-popup-examples/images/jquerybubblepopup-themes', 
      alwaysVisible: false, 
      closingDelay: 200, 
      selectable: true, 
      afterShown: function() { 
       active = false; 
       $(".jquerybubblepopup").bind("mouseenter",function() { 
        active = true; 
       }).bind("mouseleave", function() { 
        active = false; 
       }); 
      } 
     }); 
    }); 
    $(window).bind('click',function() { 
     resetActiveBubble(); 
    }); 
}); 
function resetActiveBubble() { 
    if (button && active == false) { 
     button.RemoveBubblePopup(); 
     button.CreateBubblePopup({ 
      manageMouseEvents: false 
     });  
    } 
} 

上面的代碼有一個窗口點擊偵聽器和一個布爾變量來確定氣泡是否「活動」或不是(例如鼠標坐在氣泡上)。

這個解決方案不會解決ipads等(你需要觸摸監聽器),當使用jsfiddle時,你仍然可以通過在加載過程中點擊來關閉它;激活狀態直到afterShown被觸發纔會被連接。

我相信它可以優化(也請注意jsfiddle中的console.logs)。我希望這有幫助。

+0

我愛你..... – KingKongFrog 2013-04-27 03:16:03