Modal Bootstrap添加动画

时间:2016-10-06 17:51:51

标签: javascript twitter-bootstrap bootstrap-modal

我正在使用标准模态引导程序,我想在单击背景时添加动作,我的模态必须使shake 行动。我该怎么做?请帮帮我。 我使用<script src="/Content/bootstrap/dist/js/bootstrap.js" type="text/javascript"></script>

<div id="static" class="panel panel panel-info modal fade" tabindex="-1" role="dialog" data-backdrop="static" style="display: none;">
<div class="panel-heading">
    info
</div>
<div class="panel-body">
    <div class="modal-body">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">

            </div>
        </div>
        <br />
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">                         
                <asp:TextBox runat="server" ID="testе" ></asp:TextBox>
            </div>
        </div>
    </div>
</div>
<div class="modal-footer">
    <div class="col-xs-4 col-sm-4 col-md-4 text-left">
        <button type="button" data-dismiss="modal" class="btn btn-link">close</button>
    </div>
    <div class="col-xs-8 col-sm-8 col-md-8 text-right">
        <asp:Button ID="btnDownload" runat="server"  OnClick="btnDownload_Click" class="btn btn-success" Text="downl"></asp:Button>

    </div>
</div>

1 个答案:

答案 0 :(得分:0)

使用animate.css这很简单。只需使用Bootstrap Modal事件检查事件目标,并将shake类添加到.modal-dialog元素。听取animationend,您可以在动画结束后删除shake课程。

这是一个例子。

&#13;
&#13;
var $modal = $('#modal-demo'),
    $btn = $('#open-modal-btn');

$modal.modal({
  keyboard: false,
  backdrop: 'static',
  show: false
})

$btn.on('click', function() {
  $modal.modal('show');
})

$modal.on('shown.bs.modal', function () {
  $(this).on('click', function(e) {
    if(e.target.id === 'modal-demo') {
      var $dialog = $(this).find('.modal-dialog');
      $dialog.addClass('shake');
      $dialog.one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
        $dialog.removeClass('shake');
      });      
    }
  })
})

$modal.on('hidden.bs.modal', function () {
  $(this).off('click');
})
&#13;
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
@import url('https://cdn.jsdelivr.net/animatecss/3.5.2/animate.min.css');
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<button type="button" class="btn btn-primary btn-lg" id="open-modal-btn">
  Launch demo modal
</button>

<div id="modal-demo" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog animated" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
&#13;
&#13;
&#13;