覆盖bootstrap模式关闭过渡效果到fadeout slow

时间:2017-06-19 12:21:16

标签: jquery css twitter-bootstrap

为了设计起见,我将Bootstrap modal transition自定义为类似下面的代码,但在关闭模态时,它会在没有过渡的情况下快速消失。问题是,如何在关闭所有模态时添加过渡淡出效果?任何帮助将不胜感激。

CSS:

.fade-custom {
  opacity: 0;
  -webkit-transition: all .30s linear;
  -o-transition: all .30s linear;
  transition: all .30s linear;
  transform: scale(0);
}

.fade-custom.in {
  opacity: 1;
  transform: scale(1);
}

注意:我尝试过jquery来处理fadeOut,但没有运气。

$( ".close-help" ).click(function() {
  $( "#helpReviewers" ).fadeOut( "slow", function() {
  });
});

演示:



.fade-custom {
  opacity: 0;
  -webkit-transition: all .30s linear;
  -o-transition: all .30s linear;
  transition: all .30s linear;
  transform: scale(0);
}

.fade-custom.in {
  opacity: 1;
  transform: scale(1);
}

<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>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>


<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade-custom" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close " data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

试试这个CSS

.fade-custom {
  -webkit-transition: all .30s linear !important ;
  -o-transition: all .30s linear !important ;
  transition: all .30s linear !important ;
  transform: scale(0) !important ;
}

.fade.in {
  transform: scale(1) !important ;
}

也不要从HTML代码中删除fade类。否则,引导效果将不起作用。

DEMO HERE https://jsfiddle.net/9w0gstq4/