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

JS APl关于电梯导航做法(ES6)

文章目录

文章目录

需求:

整体架构流程

技术名词解释

代码展示:

小结


需求:

1.点击哪个模块可以跳转的对应的模块

2.点击哪个模块对应的模块显示高亮(就是哪个盒子背景色变红色)

整体架构流程

// 1. 获元取素

document.querySelectorAll

// 2.内容的盒子获取

//3.. 左侧aside 模块 点击谁,谁高亮

这里用到冒泡就是获取父盒子就可以

//4.// 找到上一个active 移除类

例如:
在语言模型中,编码器和解码器都是由一个个的 Transformer 组件拼接在一起形成的。

技术名词解释

例如:

  • querySelectorAll(获取元素 但是返回是一组伪数组)
  • querySelector(获取元素)
  • this.classList.add(追加类)
  • document.documentElement.scrollTop(整个盒子被卷去的举例)

代码展示:

HTML: 

  <div class="aside">
        <div class="item active">男装/女装</div>
        <div class="item">儿童服装/游乐园</div>
        <div class="item">电子产品</div>
        <div class="item">电影/美食</div>
    </div>

    <div class="content">
        <div class="neirong content1">男装/女装</div>
        <div class="neirong content2">儿童服装/游乐园</div>
        <div class="neirong content3">电子产品</div>
        <div class="neirong content4">电影/美食</div>
    </div>

css:

 <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            height: 3000px;
        }

        .aside {
            position: fixed;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
        }

        .item {
            height: 40px;
            line-height: 40px;
            text-align: center;
            padding: 0 10px;
            cursor: pointer;
        }

        .active {
            background-color: red;
            color: #fff;
        }

        .content {
            width: 660px;
            margin: 400px auto;
        }

        .neirong {
            height: 300px;
            margin-bottom: 20px;
            color: #fff;
        }

        .content1 {
            background-color: red;
        }

        .content2 {
            background-color: blue;
        }

        .content3 {
            background-color: orange;
        }

        .content4 {
            background-color: yellowgreen;
        }
    </style>

 

 <script>

        // 1. 获元取素  
        const items = document.querySelectorAll('.item')
        // 内容的盒子获取
        const neirongs = document.querySelectorAll('.neirong')
        // 2. 左侧aside 模块 点击谁,谁高亮
        for (let i = 0; i < items.length; i++) {
            items[i].addEventListener('click', function () {
                // 找到上一个active 移除类
                document.querySelector('.aside .active').classList.remove('active')
                // 点击谁谁添加类
                this.classList.add('active')
                // 3. 右侧内容跟随走动  让页面滚动到对应的offsetTop值位置
                // console.log(neirongs[i].offsetTop) 不用给单位
                document.documentElement.scrollTop = neirongs[i].offsetTop
            })
        }

    </script>

 

 

小结:

我们需要实现点击某一个按钮,然后滚动到对应的区域。 滚动的时候,右侧对应的分类实现高亮 其实,这个功能就2个步骤: 1.点击元素高亮,滚动到对应区域 


http://www.kler.cn/news/162406.html

相关文章:

  • 正则表达式详细讲解
  • openEuler JDK21 部署 Zookeeper 集群
  • 盘点11月Sui生态发展,了解Sui的近期成长历程!
  • springboot3.0更新后,idea创建springboot2.x项目
  • js写旋转的时钟动态
  • 在Windows 10或11中,复制和粘贴不起作用,不一定是键盘的问题
  • canvas基础:绘制虚线
  • Python 爬虫 之scrapy 框架
  • SAP 后继物料简介
  • promethesu告警规则配置,alertmanager通过webhook通知
  • 使用Rust 构建C 组件
  • php爬虫规则与robots.txt讲解
  • HarmonyOs 4 (二) HelloWord
  • (1)(1.4) ESP32 wifi telemetry
  • Unity 性能优化的手段【更新中】
  • 前端组件库开发
  • 【开题报告】基于SpringBoot的影视作品网站的设计与实现
  • 利用异或、取反、自增bypass_webshell_waf
  • 电脑出现错误代码0xc000000f怎么办,有效解决0xc000000f问题
  • [wp]“古剑山”第一届全国大学生网络攻防大赛 Web部分wp
  • Python-滑雪大冒险【附源码】
  • uni-app解决video组件全屏时页面横竖错乱问题
  • Fiddler的配置、原理和使用
  • 爬虫-BeautifulSoup之XML篇
  • synxflow 安装环境
  • es6 相关面试总结
  • k8s引用环境变量
  • js数组删除某个元素
  • JS如何实现竖屏轮播图
  • 机器学习应用 | 使用 MATLAB 进行异常检测(上)