Bootstrap 4的平滑动画崩溃

时间:2018-08-22 07:48:48

标签: html css css3 bootstrap-4 css-transitions

我找到了想要的东西,但是动画效果并不理想。我知道如果没有mfcol,动画会更好,但是我需要填充来获得设计。我该如何解决这个问题?

JSFiddle DEMO

HTML:

splitscreen

CSS:

padding

这基于最新版本的Bootstrap 4。

2 个答案:

答案 0 :(得分:1)

设置.collapse时,它会先应用.collapse的引导程序样式,然后再应用,因为会有延迟...

使用ID #collapseExample设置样式:

.block {
  margin-top: 30px;
}
#collapseExample{
  background-color: #eee;
  padding: 30px 15px;
}
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <div class="block">
            <label class="checkbox"> This is my checkbox
              <input type="checkbox" data-toggle="collapse" data-target="#collapseExample">
            </label>
            <div class="collapse" id="collapseExample">
              <div class="row">
                <div class="col-12">
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option one">
                  </div>
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option two">
                  </div>
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option three">
                  </div>
                </div>
              </div>
            </div>
      </div>
    </div>
  </div>
</div>

编辑您的评论!

  

关闭时会有一个“拖动”。

使用jquery onclick checkbox并按如下所示应用paddingfiddle here

$('.checkbox').on('click', function(){
if($('.collapse.show').length>0)
    $('.collapse').css('padding','0');
else
    $('.collapse').css('padding','30px 15px');
    
});
.block {
  margin-top: 30px;
}
#collapseExample{
  background-color: #eee;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <div class="block">
            <label class="checkbox"> This is my checkbox
              <input type="checkbox" data-toggle="collapse" data-target="#collapseExample">
            </label>
            <div class="collapse" id="collapseExample">
              <div class="row">
                <div class="col-12">
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option one">
                  </div>
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option two">
                  </div>
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option three">
                  </div>
                </div>
              </div>
            </div>
      </div>
    </div>
  </div>
</div>

答案 1 :(得分:0)

我解决了。这是因为我在父div中添加了padding

.block {
  margin-top: 30px;
}
.block__collapse {
  background-color: #eee;
  padding: 30px 15px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <div class="block">
            <label class="checkbox"> This is my checkbox
              <input type="checkbox" data-toggle="collapse" data-target="#collapseExample">
            </label>
            <div class="collapse" id="collapseExample">
            <div class="block__collapse">
              <div class="row">
                <div class="col-12">
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option one">
                  </div>
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option two">
                  </div>
                  <div class="form-group">
                    <input type="number" class="form-control" placeholder="option three">
                  </div>
                </div>
              </div>
            </div>
            </div>
      </div>
    </div>
  </div>
</div>