39.手机导航

手机导航

html部分

复制代码
<div class="phone">
    <div class="content">
        <img class="active" src="./static/20180529205331_yhGyf.jpeg" alt="" srcset="">
        <img src="./static/20190214214253_hsjqw.webp" alt="" srcset="">
        <img src="./static/20190908084721_rjhtr.png" alt="" srcset="">
        <img src="./static/20210210111704_cd68b.jpg" alt="" srcset="">
    </div>
    <div class="nav">
        <div class="">
            <i  class="iconfont icon-home-fill active"></i>
        </div>
        <div class="">
            <i class="iconfont icon-calendar-fill"></i>
        </div>
        <div class="">
            <i class="iconfont icon-picture-fill"></i>
        </div>
        <div class="">
            <i class="iconfont icon-camera-fill"></i>
        </div>
    </div>
</div>

css部分

复制代码
*{
    margin: 0;
    padding: 0;
}
body{
    background-color: rgb(184, 138, 203);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}
img{
    width: 350px;
    height: 550px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    object-fit: cover;
    position: absolute;
    transition: all .5s;
    opacity: 0;
}
img.active{
    opacity: 1;
}

.phone{
    height: 600px;
    width: 350px;
    padding: 2px;
    border-radius: 10px;
    background-color: #fff;
}
.content{
    overflow: hidden;
    height: 550px;
    position: relative;
}
.nav{
    padding: 10px;
    display: flex;
    justify-content: space-around;
}
i{
    font-size: 24px !important;
    color: #777777;
    cursor: pointer;
}
i.active{
    color: #8e44ad !important;
}

js部分

复制代码
// 获取dom
const is = document.querySelectorAll("i")
const imgs = document.querySelectorAll("img")


is.forEach((item, index) => {
    item.addEventListener("click", function () {
        // 如果非活动状态添加活动类
        if (!item.classList.contains("active")) {
            item.classList.add("active")
            imgs[index].classList.add("active")
        }

        // 移除其他元素的活动类
        is.forEach((sub, idx) => {
            if (index != idx) {
                sub.classList.remove("active")
            }
        })
        imgs.forEach((sub, idx) => {
            if (index != idx) {
                sub.classList.remove("active")
            }
        })
    }
    )
})

效果

相关推荐
fengci.9 分钟前
Microweber CMS 未授权路径穿越漏洞(CVE-2026-65694)
android·开发语言·前端·学习·php
Deryck_德瑞克13 分钟前
【Nginx】配置差异分析
服务器·前端·nginx
前端 贾公子20 分钟前
第06章:结构化输出 (上)
java·服务器·前端
北斗落凡尘24 分钟前
React面试题
前端
一棵白菜1 小时前
mac 部署 n8n
前端
学高数就犯困1 小时前
React:常见的性能优化手段
前端·react.js
天天码行空1 小时前
vkeyboardhand:零依赖虚拟键盘指法组件
前端·javascript·vue.js
东方小月1 小时前
从零开发一个 Coding Agent(五):使用 TypeBox 校验工具参数
前端·人工智能·后端
我要两颗404西柚1 小时前
Stage four:VUE项目上线
前端·javascript·vue.js
尤乐娃子1 小时前
进入大厂(厂子大)实习Day8
前端·笔记·实习