2013-04-26 79 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