Vue實(shí)現(xiàn)導(dǎo)航吸頂效果的教程詳解
在瀏覽器上下滾動的時(shí)候,如何距離的頂部的距離大于78px,吸頂顯示,小于78px則隱藏
工具類安裝:npm i @vueuse/core
創(chuàng)建吸頂頁面 fixed.vue:
<script setup> // vueUse import { useScroll } from '@vueuse/core' const { y } = useScroll(window) </script> <template> <div class="app-header-sticky" :class="{ show: y > 78 }"> <div class="container"> <RouterLink class="logo" to="/" /> <!-- 導(dǎo)航區(qū)域 --> <div class="right"> <RouterLink to="/">品牌</RouterLink> <RouterLink to="/">專題</RouterLink> </div> </div> </div> </template> <style scoped lang='scss'> .app-header-sticky { width: 100%; height: 80px; position: fixed; left: 0; top: 0; z-index: 999; background-color: #fff; border-bottom: 1px solid #e4e4e4; // 此處為關(guān)鍵樣式!!! // 狀態(tài)一:往上平移自身高度 + 完全透明 transform: translateY(-100%); opacity: 0; // 狀態(tài)二:移除平移 + 完全不透明 &.show { transition: all 0.3s linear; transform: none; opacity: 1; } .container { display: flex; align-items: center; } .logo { width: 200px; height: 80px; background: url("@/assets/images/logo.png") no-repeat right 2px; background-size: 160px auto; } .right { width: 220px; display: flex; text-align: center; padding-left: 40px; border-left: 2px solid $xtxColor; a { width: 38px; margin-right: 40px; font-size: 16px; line-height: 1; &:hover { color: $xtxColor; } } } } </style>
引用該組件:
效果:
到此這篇關(guān)于Vue設(shè)置導(dǎo)航吸頂?shù)慕坛淘斀獾奈恼戮徒榻B到這了,更多相關(guān)Vue設(shè)置導(dǎo)航吸頂內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue+axios實(shí)現(xiàn)post文件下載
這篇文章主要為大家詳細(xì)介紹了vue+axios實(shí)現(xiàn)post文件下載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-09-09vue2.0 better-scroll 實(shí)現(xiàn)移動端滑動的示例代碼
本篇文章主要介紹了vue2.0 better-scroll 實(shí)現(xiàn)移動端滑動的示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2018-01-01vue計(jì)算屬性computed--getter和setter用法
這篇文章主要介紹了vue計(jì)算屬性computed--getter和setter用法,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01利用vue組件實(shí)現(xiàn)圖片的拖拽和縮放功能
這篇文章主要給大家介紹了關(guān)于利用vue組件實(shí)現(xiàn)圖片的拖拽和縮放功能的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-01-01