Abstract: Accordion (also known as "drawer") effect is named after its expansion style that looks like an accordion. Through hierarchical relationships, a clever balance is achieved in information display and page layout. Therefore, it is widely used in Web and App interaction design. In previous projects, Accordion was usually implemented by JavaScript coding. This sharing focuses on exploring two methods that do not rely on JS and use pure CSS3 or HTML5 to achieve their effects. And make a preliminary comparison of its advantages and disadvantages.
Traditional JS implementation method
1. Native JavaScript
2. Calling JS library files, jQuery, jQuery Mobile
$'.menu_lev1').clickfunction) { var _this=$this), _next=_this.next); if _next.is':visible')) { $'.menu_lev1').removeClass'on'); $'.menu_lev2').slideUp600); _this.addClass'on'); _next.slideDown600); } else { _next.slideUp600); _this.removeClass'on'); } return true; });
Disadvantages of copying code: low efficiency, high cost, behavior and style are tightly coupled.
CSS3 Pseudo-class: target
target is one of new pseudo-classes in CSS3. It can add specified styles to the target element through anchor. Because of the uniqueness of the anchor points in the page, mutually exclusive rotation effects can be achieved.
Sample code 1: h1 first-level directory/h1>
ul id="ac1"> li>二级菜单1/li> li>二级菜单2/li> li>二级菜单3/li> /ul>
Copy code
ul{ display:none;} ul:target{display:block;}
Copy codeExample code 2: c1">First-level directory/a>/ h1>
ul id="ac1"> li>二级菜单1/li> li>二级菜单2/li> li>二级菜单3/li> /ul> h1>2">一级目录/a>/h1> ul id="ac2"> li>二级菜单1/li> li>二级菜单2/li> li>二级菜单3/li> /ul> h1>一级目录/a>/h1> ul id="ac3"> li>二级菜单1/li> li>二级菜单2/li> li>二级菜单3/li> /ul>
Copy code
ul{ display:none;} ul:target{display:block;}
Copy code Sample code 3: div id="ac1" >
h1>a >一级目录/a>span>/span>/h1> ul> li>二级菜单1/li> li>二级菜单2/li> /ul> /div> div id="ac2" > h1>a >一级目录/a>span>/span>/h1> ul> li>二级菜单1/li> li>二级菜单2/li> /ul> /div> div id="ac3" > h1>a 3">一级目录/a>span>/span>/h1> ul> li>二级菜单1/li> li>二级菜单2/li> /ul> /div>
Copy code
ul{-webkit-transition:all ease 1s; } div:target ul{height:400px;} div:target span{-webkit-transform:rotate90deg);}
Copy code Css3 pseudo-class: targetl Disadvantages: 1. No duality. 2. Transition animation height cannot be obtained automatically.
HTML5 tag summary & details
##summary & details. are two new tags in HTML5. In addition to having strong Sample code 1: details>summary>一级目录/summary> ul> li>二级菜单/li> li>二级菜单/li> li>二级菜单/li> /ul> /details>
summary>一级目录/summary> ul> li>二级菜单/li> li>二级菜单/li> li>二级菜单/li> /ul> details> summary>二级菜单/summary> ul> li>三级菜单/li> li>三级菜单/li> li>三级菜单/li> /ul> /details> /details>
details summary::-webkit-details-marker {background: red;color: #fff;font-size: 200%;} summary::-webkit-details-marker { display: none } summary:after { content: "+";} details[open] summary:after {content: "-";}
The above is the detailed content of Detailed explanation of the exploration of the three effects of accordion in HTML5 applications. For more information, please follow other related articles on the PHP Chinese website!