js 底部导航栏切换 (炫酷效果)

js 底部导航栏切换 (炫酷效果)

在这里插入图片描述
在这里插入图片描述

直接上代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    :root{
        --color:#222327;
    }
    *{
        padding: 0;
        margin: 0;
        box-sizing: border-box;
    }
    body{
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 100vh;
        background: var(--color);
    }
    .container{
        width: 440px;
        height: 70px;
        background: #fff;
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 10px;
        position: relative;
    }
    .item{
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        width: 100px;
        
    }
    img{
        width: 30px;
        height: 30px;
        position: absolute;
        font-size: 1.7em;
        transition: .5s;
    }
    .text{
        transform: translateY(20px);
        font-size: 0.75em;
        font-weight: bold;
        transition: .5s;
        opacity: 0;
    }
    .item.active img{
        transform: translateY(-32px);
        z-index: 1;
    }
    .item.active .text{
        opacity: 1;
        transform: translateY(10px);
    }
    .indicator{
        position: absolute;
        width: 70px;
        height: 70px;
        background: rgb(18, 212, 50);
        left:35px;
        top:-50%;
        border-radius: 50%;
        border:6px solid var(--color);
        transition: .5s;
    }
    .indicator::before{
        content: '';
        position: absolute;
        top: 50%;
        left: -22px;
        width: 20px;
        height: 20px;
        background: transparent;
        border-top-right-radius: 20px;
        box-shadow: 0 -10px 0 0 var(--color);
    }
    .indicator::after{
        content: '';
        position: absolute;
        top: 50%;
        right: -22px;
        width: 20px;
        height: 20px;
        background: transparent;
        border-top-left-radius: 20px;
        box-shadow: 0 -10px 0 0 var(--color);
    }
    .item:nth-child(1).active ~ .indicator {
        transform:translateX(calc(100px  * 0));
    }
    .item:nth-child(2).active ~ .indicator {
        transform:translateX(calc(100px  * 1));
    }
    .item:nth-child(3).active ~ .indicator {
        transform:translateX(calc(100px  * 2));
    }
    .item:nth-child(4).active ~ .indicator {
        transform:translateX(calc(100px  * 3));
    }
</style>
<body>
    <div class="container">
        <div class="item active">
            <img src="https://s1.ax1x.com/2022/04/23/LffnC8.png" alt="">
            <div class="text">首页</div>
        </div>
        <div class="item">
            <img src="https://s1.ax1x.com/2022/04/23/Lffu8S.png" alt="">
            <div class="text">分类</div>
        </div>
        <div class="item">
            <img src="https://s1.ax1x.com/2022/04/23/LffKgg.png" alt="">
            <div class="text">更多</div>
        </div>
        <div class="item">
            <img src="https://s1.ax1x.com/2022/04/23/LffMvQ.png" alt="">
            <div class="text">我的</div>
        </div>
        <div class="indicator"></div>
    </div>
</body>
<script>
    const list = document.querySelectorAll('.item')
    console.log(list);
    function activeLike(){
        list.forEach((item) => 
            item.classList.remove('active'))
        this.classList.add('active')
    }
    list.forEach((item) =>  item.addEventListener('click',activeLike))
</script>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vue1024

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值