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")
            }
        })
    }
    )
})

效果

相关推荐
烛阴1 小时前
Python装饰器解除:如何让被装饰的函数重获自由?
前端·python
千鼎数字孪生-可视化1 小时前
Web技术栈重塑HMI开发:HTML5+WebGL的轻量化实践路径
前端·html5·webgl
凌辰揽月1 小时前
7月10号总结 (1)
前端·css·css3
天天扭码2 小时前
很全面的前端面试——CSS篇(上)
前端·css·面试
EndingCoder2 小时前
搜索算法在前端的实践
前端·算法·性能优化·状态模式·搜索算法
sunbyte2 小时前
50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | DoubleVerticalSlider(双垂直滑块)
前端·javascript·css·vue.js·vue
Favor_Yang2 小时前
SQL Server通过存储过程实现HTML页面生成
前端·信息可视化·sqlserver·存储过程
中微子3 小时前
JavaScript事件循环机制:面试官最爱问的10个问题详解
前端
Eighteen Z3 小时前
CSS揭秘:10.平行四边形
前端·css·css3
拾光拾趣录3 小时前
虚拟DOM
前端·vue.js·dom