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

效果

相关推荐
Struggler2811 分钟前
pinia-基于monorepo的项目结构管理
前端
Struggler2815 分钟前
SSE的使用
前端
用户58061393930012 分钟前
前端文件下载实现深度解析:Blob与ObjectURL的完美协作
前端
Lin866615 分钟前
Vue 3 + TypeScript 组件类型推断失败问题完整解决方案
前端
coding随想15 分钟前
从零开始:前端开发者的SEO优化入门与实战
前端
前端工作日常18 分钟前
我理解的JSBridge
前端
Au_ust18 分钟前
前端模块化
前端
顺丰同城前端技术团队18 分钟前
还不会用 Charles?最后一遍了啊!
前端
BUG收容所所长19 分钟前
二分查找的「左右为难」:如何优雅地找到数组中元素的首尾位置
前端·javascript·算法
彬师傅20 分钟前
geojson、csv、json 数据加载
前端