当前位置: 首页 > news >正文

html ul li 首页渲染多条数据 但只展示八条,其余的数据全部隐藏,通过icon图标 进行展示

   <div  style="float: left;" id="showMore"> 展开 </div>

 <div  style="float: left;“id="hideLess"> 收起 </div>

var data = document.querySelectorAll('.allbox .item h3 a');

        const list = document.querySelectorAll('.all-sort-list .item h3 a');

        data.forEach((item, index) => {

            if (index === 7) {

                document.querySelector("#showMore").style.display = "block"

            }

        });

            var listItems = document.querySelectorAll('.all-sort-list .item');

            if (listItems.length > 8) {

                for (var i = 8; i < listItems.length; i++) {

                    listItems[i].style.display = 'none';

                }

                document.getElementById('showMore').style.display = 'block';

                document.getElementById('hideLess').style.display = 'none';

            }

    //    展开

        document.getElementById('showMore').addEventListener('click', function () {

            var listItems = document.querySelectorAll('.allbox .item');  

            if (listItems.length > 8) {

                for (var i = 8; i < listItems.length; i++) {

                    listItems[i].style.display = 'block';  

                    listItems[i].className+= " wrap_item";  

                }

                document.getElementById('showMore').style.display = 'none';

                document.getElementById('hideLess').style.display = 'block';

            }  

        });

        // 收起

        document.getElementById('hideLess').addEventListener('click', function () {

            var listItems = document.querySelectorAll('.all-sort-list .item');

            if (listItems.length > 8) {

                for (var i = 8; i < listItems.length; i++) {

                    listItems[i].style.display = 'none';

                }

                document.getElementById('showMore').style.display = 'block';

                document.getElementById('hideLess').style.display = 'none';

            }

        });

        .wrap1 {

            bottom: 0px;

            left: 0px;

            float: left;

            position: relative;

            z-index: 3;

            width: 198px;

            height: 100%;

            background: #2a86dd;

        }

        .allbox {

            position: relative;

            width: 195px;

            border: 1px solid #2a86dd;

            border-top: none;

            padding: 1px;

        }

        #showMore {  

            display: inline-block;

            width: 20px;

            height: 20px;  

            color: #fff; 

            display: none;  

        }

        #hideLess{  

            display: inline-block;

            width: 20px;

            height: 20px;   

         color: #fff;

            display: none;  

        }

 .item:hover #showMore {

    color: #f00;

 }

 .item:hover #hideLess {

    color: #f00;

 }

 .wrap_item{

    width: 200px;

    height: 45px;

    line-height: 45px;

    background-color: #09f;

    color: #fff;

 }

数据结构

   <div class="boxCur">

            <div class="wrap1">

                <div class="allbox">

                    <div class="item bo">

http://www.lryc.cn/news/498381.html

相关文章:

  • Facebook:筑牢隐私安全堡垒,守护社交净土
  • 2024年构建PHP应用开发环境
  • Apache Commons Chain 与 Spring Boot 整合:构建用户注册处理链
  • 一、测试工具LoadRunner Professional脚本编写-录制前设置
  • React Native 组件详解之SectionList、StatusBar、Switch、Text 、 TextInput
  • 阿里云:aliyun-cli和ali-instance-cli
  • Linux 远程连接服务
  • Docker 安装和使用
  • web基础和http协议 附:nginx服务的安装
  • springboot利用easypoi实现简单导出Excel
  • 【前端新手小白】学习Javascript的【开源好项目】推荐
  • CentOS7虚拟机 网络适配器 NAT模式和桥接模式区别
  • sql删除冗余数据
  • STM32-C语言基础知识
  • 【Point-LIO】基于Ubuntu20.04的ROS1平台的Point-LIO部署Mid-360激光雷达
  • 02_Node.js模块化
  • 网络——HTTP与HTTPS三次握手和四次挥手
  • ModelScope-Agent(1): 基于开源大语言模型的可定制Agent系统
  • 开发知识点-uniCloud
  • Redis——主从复制原理
  • MATLAB数学建模之画图汇总
  • Milvus attu - docker 使用 及 版本兼容
  • okHttp的tcp连接池的复用
  • nginx 自启动失败:Failed to parse PID from file: Invalid argument
  • Wwise SoundBanks内存优化
  • centos 常见问题处理
  • 简述Vue每个周期具体适合哪些场景?
  • Alibaba Druid(简称Druid)
  • linux protobuf的安装与使用
  • 关于Chrome自动同步书签的解决办法