Home Web Front-end H5 Tutorial Detailed explanation of the exploration of the three effects of accordion in HTML5 applications

Detailed explanation of the exploration of the three effects of accordion in HTML5 applications

Mar 31, 2017 pm 01:47 PM

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;

});
Copy after login

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

Copy code

ul{ display:none;}

ul:target{display:block;}
Copy after login
Copy after login

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

Copy code

ul{ display:none;}

ul:target{display:block;}
Copy after login
Copy after login

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

Copy code

ul{-webkit-transition:all ease 1s; } 

div:target ul{height:400px;}

div:target span{-webkit-transform:rotate90deg);}
Copy after login

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

semantic, they also have surprising dynamic effects. Therefore, we can easily create them by seizing this feature. Lightweight accordion effect. Generally speaking, these two tags should be used in pairs.

Sample code 1: details>

 summary>一级目录/summary>  

       ul>

            li>二级菜单/li>

            li>二级菜单/li>

            li>二级菜单/li>

       /ul> 

/details>
Copy after login

Copy code Default style: You can add open to details.

Attribute, so that the details are expanded by default. This tag is currently only supported by the webkit kernel.

Sample code 2: details>

  summary>一级目录/summary>  

       ul>

            li>二级菜单/li>

            li>二级菜单/li>

            li>二级菜单/li>

       /ul> 

      details>

            summary>二级菜单/summary>  

           ul>

               li>三级菜单/li>

               li>三级菜单/li>

               li>三级菜单/li>

           /ul> 

      /details>  

/details>
Copy after login

Copy code description: It can be nested to form. Three-level and more-level menus.

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: "-";}
Copy after login
Disadvantages of copying the code: 1. Not mutually exclusive. 2. The transition animation effect is not currently supported.

Summary JS implements the accordion effect. The cost is high and the efficiency is low. Currently, CSS3 can achieve the richest effect. It has low cost and high efficiency. Although it can achieve rich animation effects, HTML5 does not have the duality to achieve the accordion effect and has low cost. High efficiency, but lacks animation effects and is not mutually exclusive. The currently supported browser cores are limited

Looking forward to the introduction and development of CSS3 and HTML5, which will further promote the structure, style, and behavior to some extent. The concept of web design that is separated from others. This reduces the dependence on JS in performance, reduces the cost of web page production, and improves the efficiency of web page operation. There is no reason not to expect that CSS3 and HTML5 will continue to improve and provide more powerful functions in the future.

Recommendation

In web apps with a lot of content, based on the principle of performance priority, gracefully degrade appropriately and use HTML5 tags to achieve the Accordion effect. At least the author of Html5doctor prefers it in WordPress.

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles