vue实现吸顶效果

 html:

<div class="pc_header">
            <header :class="{ 'sticky': isSticky }">
                <div class="logo"></div>
                <ul>
                    <li><a @click="navJump(1)">首页</a></li>
                    <li class="drop_down"><a @click="navJump(2)">平台信息</a>
                        <div class="down_box">
                            <ul class="options">
                                <li><a>方案</a></li>
                                <li><a>方案</a></li>
                                <li><a>方案</a></li>
                                <li><a>方案</a></li>
                            </ul>
                        </div>
                    </li>
                    <li><a @click="navJump(3)">业务体系</a></li>
                    <li><a @click="navJump(4)">发展规划</a></li>
                    <li><a @click="navJump(5)">工作台</a></li>
                </ul>
            </header>
        </div>

JS:

<script>
export default {
    data() {
        return {
            isSticky: false,
        }
    },
    mounted() {
        window.addEventListener("scroll", this.handleScroll);
    },
    beforeDestroy() {
        window.removeEventListener("scroll", this.handleScroll);
    },
    methods: {
        // 监听滚轮事件
        handleScroll() {
            this.isSticky = window.scrollY > 0;
        }
    }
}
</script>

CSS:

/* 吸顶效果css */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    word-wrap: break-word;
    font-family: '微软雅黑', sans-serif;
}

header {
    position: fixed;
    top: 40px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 30px 150px;
    z-index: 999;
    transition: 0.6s;
    align-items: center;
}

header.sticky {
    padding: 10px 150px;
    background-color: #fff;
    top: 0;
    align-items: center;
}
/* 下拉css */

header .logo {
    position: relative;
    transition: 0;
    width: 150px;
    height: 39px;
    background-image: url('@/static/images/logo.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

header ul {
    position: relative;
    display: flex;
    justify-content: center;
}

header ul li {
    position: relative;
    list-style: none;
}

header ul li a {
    position: relative;
    margin: 0 20px;
    text-decoration: none;
    color: #000;
    letter-spacing: 2px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.3s;
}

header ul li a:hover {
    color: rgb(114, 114, 114);
    transition: 0.3s;
}

header.sticky .logo,
header.sticky ul li a {
    color: #000;
}

.menu img {
    width: 35px;
    height: 35px;
}

.menu_list {
    margin-left: 20px;
}

.menu_list li {
    line-height: 40px;
    list-style: none;
    cursor: pointer;
}

@media screen and (max-width: 965px) {
    .pc_header {
        transition: opacity 1s ease-in-out;
        display: none;
    }

    header {
        padding: 10px 27px;
    }

    header.sticky {
        padding: 10px 27px;
    }

    header .logo {
        width: 100px;
        height: 27px;
    }
}

@media screen and (min-width: 965px) {
    .phone_header {
        display: none;
        transition: opacity 1s ease-in-out;
    }
}

.drop_down {
    position: relative;
}

.down_box {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    width: 250px;
    height: 0px;
    overflow: hidden;
    transition: all 0.4s;
    background-color: aqua;

    .options {
        display: block !important;
    }
}

.drop_down:hover .down_box {
    height: 200px;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值