zoukankan      html  css  js  c++  java
  • js 实现手风琴

    <!DOCTYPE html>
    <html lang="en">

    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>手风琴</title>
    <style>
    * {
    margin: 0;
    padding: 0;
    }
     
    ul li {
    list-style: none;
    text-align: center;
    }
     
    li {
    150px;
    height: 30px;
    line-height: 30px;
    cursor: pointer;
    border-bottom: 1px solid #fff;
    }
     
    li h3 {
    border-bottom: 1px solid #fff;
    }
     
    .wrap {
    200px;
    }
     
    .wrap .subContent {
    color: #fff;
    background: #008b8b;
    overflow: hidden;
    transition: all 2s ease 2s;
    }
     
    .details li {
    background: #333;
    }
    </style>
    <script>
    window.onload = function() {
    function p(arg) {
    console.log(arg);
    }
    let content = document.querySelector('.content'),
    subContent = content.querySelectorAll('.subContent'),
    details = content.querySelectorAll('.details');

    function ss() {
    for (let i = 0; i < subContent.length; i++) {
    subContent[i].style.height = '30px';
    (function(q) {
    subContent[q].addEventListener('click', function(ev) {
    var e = ev || window.event;
    e.stopPropagation();
    e.preventDefault();
    ss();
    detailsLi = details[i].querySelectorAll('li');
    this.style.height = 30 * (detailsLi.length + 1) + (detailsLi.length) + 'px';
    }, false);
    })(i)
    }
    }
    ss();
    }
    </script>
    </head>

    <body>
    <div class="wrap">
    <ul class="content">
    <li class="subContent">
    <h3>我是标题</h3>
    <ul class="details">
    <li>我是内容</li>
    <li>我是内容</li>
    <li>我是内容</li>
    <li>我是内容</li>
    <li>我是内容</li>
    <li>我是内容</li>
    </ul>
    </li>
    <li class="subContent">
    <h3>我是标题1</h3>
    <ul class="details">
    <li>我是内容1</li>
    <li>我是内容</li>
    <li>我是内容</li>
    <li>我是内容</li>
    </ul>
    </li>
    <li class="subContent">
    <h3>我是标题2</h3>
    <ul class="details">
    <li>我是内容2</li>
    <li>我是内容</li>
    <li>我是内容</li>
    <li>我是内容</li>
    </ul>
    </li>
    </ul>
    </div>
    </body>

    </html>
  • 相关阅读:
    Docker 基础 B站 学习 最强 教程
    apache+php安装
    php拓展 swoole 安装
    go beego框架 入门使用 (一)
    php 使用 phpword 操作 word 读取 word
    linux + MongoDB 安装 + 部署 + 讲解 (满满干货看完记得收藏噢)
    Thanos设计简析
    Prometheus TSDB文件格式-index
    Linux Kernel文件系统写I/O流程代码分析(二)bdi_writeback
    Linux Kernel文件系统写I/O流程代码分析(一)
  • 原文地址:https://www.cnblogs.com/qiaoxinming/p/8397510.html
Copyright © 2011-2022 走看看