3

我正在尝试在单击时在颜色框中显示隐藏的 div

我不知道如何在颜色框中显示 div

div 是隐藏的,但我希望它在明显地显示在颜色框内时可见

<div class="test">test</div> // on click

<div id="messageform" style="display: none;"> // show this in colorbox
TEST
</div>    



$('.test').click(function(){
$.colorbox({inline:true, width:"50%", open:true, href:"#messageform" }); 
});

这仅在表单消息表单未隐藏时才有效,但如何在颜色框中单击时显示?

4

2 回答 2

12

您可以将messageform具有的 div 包装在内部,也display:none可以将其设置为在单击时显示:

$('.test').click(function(){
  $('#messageform').show();
  $.colorbox({inline:true, width:"50%", open:true, href:"#messageform" }); 
});

这是一个带有设置为不显示的容器的演示:http: //jsfiddle.net/fbenariac/4vuDC/

您也可以使用颜色框事件来显示/隐藏:http: //jsfiddle.net/lucuma/LK4tt/1/

$('.test').click(function(){

$.colorbox({inline:true, width:"50%", open:true, href:"#messageform",
            onClosed: function() {
                 $('#messageform').hide();
            },
            onOpen: function() {
                 $('#messageform').show();
            }
           }); 
});​
于 2012-06-09T21:25:15.907 回答
1
  1. 为您希望在弹出窗口中看到的基本 div 制作叠加层。
  2. 添加样式以覆盖显示:无
  3. 然后调用你的js。JS会在popupoverlay中弹出内容...

HTML

    <a id="openpopup" href="popup" class="button">Details</a>

    <div class="popupoverlay" style="display:none">
        <div id="popup">
         some content...
        </div>
    </div>

JS

    $("#openpopup").colorbox({
        inline:true, 
        href: "#popup",
        width:666,
    });
于 2016-07-21T10:35:30.237 回答