Home > Web Front-end > JS Tutorial > body text

Bootstrap must learn folding every day_javascript skills

WBOY
Release: 2016-05-16 15:05:54
Original
1063 people have browsed it

This article mainly focuses on learning about JavaScript plug-in-folding.
1. Transition effect
About transition effects
For simple transition effects, just introduce transition.js together with other JS files. If you are using the compiled (or compressed) bootstrap.js file, there is no need to import it separately.
What's inside
Transition.js is a basic helper for the transitionEnd event and is also a simulation of CSS transition effects. It is used by other plug-ins to detect whether the current browser supports CSS transition effects.
2. Fold
Give basic styling and flexible support to components that support folding functionality, such as accordions and navigation.

Plug-in dependencies

The folding plug-in relies on the transition effect plug-in.

Case
Using the folding plug-in, a simple accordion component is built by extending the panel component.
Let’s take a look at the effect first.

Let’s take a look at the implementation of the code.

<div class="container" style="margin-top:140px;">
  <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>
Copy after login

Step one: First, the outermost layer, panel-group, includes several groups below this layer.
Step 2: Take a look at a few simple groups

<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>
Copy after login

The structure of a panel can be clearly seen through the code.
panel-header and pandl-body, and panel-header can contain titles and links. Connected to panel-body through a link.
Step 3: You can find that there is an id="accordion" in the panel-group, and then there is a data-parent="#accordion" in the link under each title below.
If removed, the effect will be that after clicking on other links, the original panel will no longer shrink.
You can show the effect of folding in another way.

 <div class="container" style="margin-top:140px;">
 <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>

Copy after login

Usage
The folding plug-in controls the style through a few simple classes
.collapse hide content
.collapse in Show content
.collapsing. It is added when the transition starts, and removed when it finishes. It probably means that the transition effect is there after the fold is added, and then it ends when it is removed.
Through data attribute
You can give a page element the ability to control collapsing simply by adding data-toggle="collapse" and data-target to it. The data-target attribute accepts a CSS selector as its control object. Make sure to add collapse class for collapsible page elements. If you want the default state of a collapsible page element to be expanded, add in class.
To add a controller to a group of collapsible page elements, add data-parent="#selector". Just refer to the example above.
Via 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" style="margin-top:240px;">

Copy after login
 <script type="text/javascript"> $(function(){
   $("#demo").collapse({
 toggle: false })
  }) 
  function Open(){
  $("#demo").collapse("show");
  }
 function Hide(){
  $("#demo").collapse("hide");
  } </script>
Copy after login

Let’s take a look at the effect above

Method
Give page elements collapsible functionality. Accepts an optional object as parameter.
$("#demo").collapse({toggle: false})
This way the element will be expanded when initialized.
1.collapse('toggle') displays or hides a collapsible page element.
2.collapse('show') displays a collapsible page element.
3.collapse('hide') hides a collapsible page element.
Event
The folding plug-in in Bootstrap exposes a set of events that can be listened to.

This binds the hidden event to the element.
The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template