1. 程式人生 > >vue實現吸頂

vue實現吸頂

ace scroll width position ott element () item listen

話不多說,看代碼。

<template>
    <div class="nav" :class="isFixed== true?‘isFixed‘:‘‘">
        <ul>
            <li @click="handlebtn()">
                綜合
                <i class="iconfont">&#xe502;</i>

            </li>
            <li>
                品牌
                
<i class="iconfont">&#xe502;</i> </li> <li> 分類 <i class="iconfont">&#xe502;</i> </li> <li> 篩選 <i class="iconfont">&#xe502;</i> </li> </ul> <!--<transition name="
move">--> <div class="one" v-if="flag"> <li>綜合排序<i class="iconfont">&#xe601;</i></li> <li>銷量從高到低</li> <li>價格從低到高</li> <li>價格從高到低</li> <li>最新商家商品</li> <li>折扣從高到低</li> </div> <!--</transition>--> </div> </template> <script> export
default { data() { return { flag: false, isFixed: "false" } }, methods: { handlebtn() { this.flag = !this.flag; }, handleScroll() { var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop if(scrollTop >44) { this.isFixed = true; } else { this.isFixed = false; } } }, mounted() { window.addEventListener(scroll, this.handleScroll) } } </script> <style scoped lang="scss"> .nav { width: 100%; height: .76rem; background: #fff; border-bottom:.01rem solid #e8e8e8; ul { width: 100%; height: 100%; display: flex; li { width: 25%; height: 100%; display: flex; justify-content: center; align-items: center; font-size: .32rem; i { font-size: .5rem; } } } .one { width: 400%; height: 5.4rem; background: #fff; li { width: 7.5rem; padding: 0 .4rem; height: .9rem; font-size: .32rem; border-top: .01rem solid #e8e8e8; color: #404040; display: flex; align-items: center; justify-content: space-between; i { font-size: .4rem; } } } } .isFixed{ position:fixed; left: 0; top:0; z-index: 10; } </style>

vue實現吸頂