您的问题的答案已经在这里给出:https://stackoverflow.com/a/18602739/1596547
collapse 插件为你的元素添加了一个 .collapsing 类,该元素具有 css3 过渡。默认情况下,过渡将高度从 0 更改为(设置或自动),因此效果将是垂直的。该插件还会在添加类之前将元素的高度设置为 0。
虽然文档中没有提到插件可以对宽度做同样的事情;将元素的宽度设置为 0 并添加一个类。要触发插件使用宽度而不是高度,您必须添加一个额外的类.width:
<div id="democontent" class="collapse width">
插件会检查这个类:
Collapse.prototype.dimension = function () {
var hasWidth = this.$element.hasClass('width')
return hasWidth ? 'width' : 'height'
}
Bootstap 的 CSS 没有为 collapse.width 提供转换,所以你必须像这样添加它:
.collapse.width {
height: auto;
-webkit-transition: width 0.35s ease;
-moz-transition: width 0.35s ease;
-o-transition: width 0.35s ease;
transition: width 0.35s ease;
}
示例,另请参阅:http://bootply.com/85690
<div class="container">
<div style="height:100px;float:left;background-color:red">
<button data-toggle="collapse" data-target="#democontent">
o<br>
p<br>
e<br>
n<br>
</button>
</div>
<div id="democontent" class="collapse width" style="height:100px;background-color:blue;color:white;">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>