Bootstrap - Div中的模态

时间:2016-03-14 14:36:04

标签: twitter-bootstrap bootstrap-modal

我正在尝试使用带有文本的透明叠加层创建一个图像块,单击图像,再次单击以隐藏。

我正在使用Bootstrap 3和Modals弹出窗口,我很难让它们出现在图像的div中。

<div class="portfolio-item">
    <a href="#" data-toggle="modal" data-target="#PortfolioWebDesignModal">
        <img class="img-portfolio img-responsive" src="img/portfolio-1.jpg">
    </a>
</div>

<div class="modal fade" id="PortfolioWebDesignModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&amp;times;</button>
            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
            </div>
            <div class="modal-body">
                <h3>Modal Body</h3>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

基于http://getbootstrap.com/javascript/#modals,我不知道如何让模式出现在特定的DIV中。

弹出窗口(http://getbootstrap.com/javascript/#popovers)可让您控制确切的位置。这是一个例子

HTML:

<div class="portfolio-item" style="width: 200px; height: 200px;">
  <a href="#" data-toggle="popover" title="Popover title">
    <img class="img-portfolio img-responsive" src="http://www.orchard.co.uk/images/portfolio.jpg">
  </a>
</div>

<div style="display: none;" id="popOverContent">
  <input type="button" value="Save" />
  <input type="button" value="Cancel" />
</div>

JQUERY:

$(function() {
  $('[data-toggle="popover"]').popover({
    html: true,
    content: function() {
      return $('#popOverContent').html();
    }
  })
});

的jsfiddle:

https://jsfiddle.net/OsborneSupremacy/xj7mrxa3/