2012-10-31 34 views
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/

感谢您的帮助!

回答

0

既然问这个,我读过这个问题jQuery Tools Alternatives?和决定,它可能是最好放弃jQuery的工具。他们网站上的论坛甚至不让你开始新的主题!