Bootstrap3.0学习教程二十四:JS插件折叠

  • 时间:
  • 浏览:1
  • 来源:5分3D-5分3D平台_5分3D网投平台

本文主要来学习一下JavaScript插件--折叠。删改教程可查看:Bootstrap3.0教程

过渡效果 

关于过渡效果

对于简单的过渡效果,只需将transition.js和其它JS文件一起去引入即可。机会你使用的是编译(或压缩)好的bootstrap.js文件,就不想再单独将其引入了。

What's inside

Transition.js是针对 is a basic helper for transitionEnd事件的另有4个 基本助手工具,也是对CSS过渡效果的模拟。它被其它插件用来检测当前浏览器对CSS过渡效果与否支持。

折叠

对为支持折叠功能的组件,同类accordions和导航,赋予基本样式和灵活的支持。

插件依赖

折叠插件依赖过渡效果插件。

案例

使用折叠插件,通过扩展panel组件从而构建了另有4个 简单的accordion组件。

先来看一下效果。

接下来看一下代码的实现。

<div class="container" >

<div class="panel-group" id="accordion">

<div class="panel panel-default">

<div class="panel-heading">

<h4 class="panel-title">

<a data-toggle="collapse" data-toggle="collapse" data-parent="#accordion" href="#collapseOne"> Collapsible Group Item </a>

</h4>

</div>

<div id="collapseOne" class="panel-collapse collapse in">

<div class="panel-body"> 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>

</div>

<div class="panel panel-default">

<div class="panel-heading">

<h4 class="panel-title">

<a data-toggle="collapse" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo"> Collapsible Group Item #2 </a>

</h4>

</div>

<div id="collapseTwo" class="panel-collapse collapse">

<div class="panel-body"> 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>

</div>

<div class="panel panel-default">

<div class="panel-heading">

<h4 class="panel-title">

<a data-toggle="collapse" data-toggle="collapse" data-parent="#accordion" href="#collapseThree"> Collapsible Group Item #3 </a>

</h4>

</div>

<div id="collapseThree" class="panel-collapse collapse">

<div class="panel-body"> 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>

</div>

</div>

</div>

第一步:首先最外面那层panel-group这层下面包括哪几块小组。

第二步:看一下哪几块简单的组

<div class="panel panel-default">

<div class="panel-heading">

<h4 class="panel-title">

<a data-toggle="collapse" data-toggle="collapse" data-parent="#accordion" href="#collapseOne"> Collapsible Group Item #1 </a>

</h4>

</div>

<div id="collapseOne" class="panel-collapse collapse in">

<div class="panel-body">

</div>

</div>

</div>

通过代码也比较清楚的不可不都可以看出另有4个 panel的形态学 。

panel-header和pandl-body,其他panel-header里面不可不都可以蕴藏标题,链接。通过链接和panel-body相连。

第三步:给你发现在panel-group蕴藏另有4个 id="accordion",其他下面每个标题下链接蕴藏个data-parent="#accordion"。

机会打上去得话,那末效果只是点击其他链接后,只是 的panel不想会再缩起来了。

给你通过只是 依据来展示折叠的效果。

<div class="container" >

<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo"> simple collapsible </button>

<div id="demo" class="collapse in">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>

用法

折叠插件通过哪几块简单的类来控制样式

.collapse 隐藏内容

.collapse  in  显示内容

.collapsing。 It  is added when the transition starts, and removed when it finishes意思大约机会只是折叠被打上去后过渡效果全是了,其他机会被移除了它就始于了了英文了。

通过data属性

仅仅通过向页面元素打上去data-toggle="collapse" 和data-target就不可不都可以为其赋予控制可折叠页面元素的能力。data-target属性接受另有4个 CSS选用器作为其控制对象。请确保为可折叠页面元素打上去collapse class。机会你希望可折叠页面元素的默认具体情况是展开的,请打上去in class。

为了给一组可折叠页面元素打上去控制器,打上去data-parent="#selector"即可。请参考里面的例子即可。

通过JavaScript

<button type="button" class="btn btn-danger" onClick="Open()">打开</button>

<button type="button" class="btn btn-danger" onClick="Hide()">折叠</button>

<div id="demo" class="collapse in">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 class="panel-group" id="accordion" >

<script type="text/javascript">

$(function(){

$("#demo").collapse({ toggle: false })

})

function Open(){

$("#demo").collapse("show");

}

function Hide(){

$("#demo").collapse("hide");

}

</script>

来看一下里面的效果

依据

赋予页面元素可折叠功能。接受另有4个 可选的object作为参数。

$("#demo").collapse({toggle: false})

只是 元素在初始化的如果来是展开的。

1.collapse('toggle')展示或隐藏另有4个 可折叠的页面元素。

2.collapse('show')展示另有4个 可折叠页面元素。

3.collapse('hide')隐藏另有4个 可折叠页面元素。

事件

Bootstrap中的折叠插件对外暴露了一组不可不都可以监听的事件。

$('#demo').on('hidden.bs.collapse', function () {

alert(1);

})

只是 就为元素绑定了隐藏时的事件。删改教程可查看:Bootstrap3.0教程