0
我試圖使用jQuery的工具疊加,和它的作品非常漂亮時,有一個靜態組推出覆蓋按鈕。附有覆蓋,多個按鈕無法找到開放疊加
然而,當鏈接到覆蓋按鈕被重新創建,覆蓋似乎變得孤立,我不明白爲什麼。我無法關閉它,並且我甚至無法通過使用each()來查看DOM的參考。
我已經看到了一些解決方案,涉及觸發一次點擊,但一兩件事,這似乎是一個不雅的解決方案,併爲其他它會導致覆蓋關閉,當我嘗試它之前閃爍。我想了解這不起作用的原因,以及一個很好的解決方案,任何人都可以提供幫助嗎?
HTML
<div id="container">
</div>
<button class='modalLaunch' rel='#modal'>
Uncontained launch button
</button>
<div id="modal">
Modal
<button id="rebuildContainer">Rebuild container</button>
</div>
的Javascript
$(document).ready(function() {
$("#modal").hide();
var rebuildContainer = function() {
$("#container").html("<button class='modalLaunch' rel='#modal'>Contained launch button 1</button><br><button class='modalLaunch' rel='#modal'>Contained launch button 2</button>");
var triggers = $(".modalLaunch").overlay({
mask: {
color: '#bbbbee',
loadSpeed: 200,
opacity: 0.9
},
closeOnClick: true,
load: false
});
}
$("#rebuildContainer").click(function() {
console.log("rebuilding buttons inside the container div");
$(".modalLaunch").each(function() {
var o = $(this).overlay();
if (o) {
console.log("there is an overlay associated with this button");
if (o.isOpened()) {
// I would expect this to be true once each time the handler is called
console.log("the overlay associated with this button is open");
}
}
});
$(".modalLaunch").overlay().close();
rebuildContainer();
});
rebuildContainer();
});
http://jsfiddle.net/EveryoneMustWin/hjJtc/
感謝您的幫助!