Vue實現(xiàn)導航吸頂效果的教程詳解
在瀏覽器上下滾動的時候,如何距離的頂部的距離大于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="/" />
<!-- 導航區(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;
// 此處為關鍵樣式!!!
// 狀態(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>
引用該組件:

效果:


到此這篇關于Vue設置導航吸頂?shù)慕坛淘斀獾奈恼戮徒榻B到這了,更多相關Vue設置導航吸頂內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Vue 實現(xiàn)v-for循環(huán)的時候更改 class的樣式名稱
這篇文章主要介紹了Vue 實現(xiàn)v-for循環(huán)的時候更改 class的樣式名稱,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
詳解Vue-Cli 異步加載數(shù)據(jù)的一些注意點
本篇文章主要介紹了詳解Vue-Cli 異步加載數(shù)據(jù)的一些注意點,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08
vue打包通過image-webpack-loader插件對圖片壓縮優(yōu)化操作
這篇文章主要介紹了vue打包通過image-webpack-loader插件對圖片壓縮優(yōu)化操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
vue實現(xiàn)動態(tài)綁定行內(nèi)樣式style的backgroundImage
這篇文章主要介紹了vue實現(xiàn)動態(tài)綁定行內(nèi)樣式style的backgroundImage方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07
Vue render渲染時間戳轉時間,時間轉時間戳及渲染進度條效果
這篇文章主要介紹了Vue render渲染時間戳轉時間,時間轉時間戳及渲染進度條效果,通過實例代碼相結合的形式給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-07-07
vue iview實現(xiàn)動態(tài)路由和權限驗證功能
這篇文章主要介紹了vue iview實現(xiàn)動態(tài)路由和權限驗證功能,動態(tài)路由控制分為兩種:一種是將所有路由數(shù)據(jù)存儲在本地文件中,另一種則是本地只存儲基本路由,具體內(nèi)容詳情大家參考下此文2018-04-04

