vue如何設(shè)置描點(diǎn)跳轉(zhuǎn)到對(duì)應(yīng)頁(yè)面
更新時(shí)間:2024年05月24日 11:48:24 作者:沐卿?
這篇文章主要介紹了vue如何設(shè)置描點(diǎn)跳轉(zhuǎn)到對(duì)應(yīng)頁(yè)面問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
vue設(shè)置描點(diǎn)跳轉(zhuǎn)到對(duì)應(yīng)頁(yè)面

<div id="app"> <a href="#target" rel="external nofollow" >點(diǎn)擊跳轉(zhuǎn)到某個(gè)位置</a> <div class="spacer"></div> <!-- 這里添加一些空間以展示效果 --> <div id="target">目標(biāo)位置</div> </div>
vue錨點(diǎn)跳轉(zhuǎn)到對(duì)應(yīng)位置(精確定位)
安裝:
npm install --save vue-scrollto
main.js引入
import Vue from 'vue'
var VueScrollTo = require('vue-scrollto');
Vue.use(VueScrollTo)頁(yè)面引用:
<template>
<div class="scrollDemo">
<div class="demoNav flex-center-center">
<div
class="demoNavItem"
v-for="(item,index) in demoNavItem"
:key="index"
:class="{navActive : idx==index}"
@click="changNav(index)"
>{{item}}</div>
</div>
<div class="demoContent">
<!-- 如果內(nèi)容為循環(huán),id則定義為:id="'demoItem'+index" -->
<div class="demoItem0 demoItem" id="demoItem0">谷歌瀏覽器內(nèi)容</div>
<div class="demoItem1 demoItem" id="demoItem1">uc瀏覽器內(nèi)容</div>
<div class="demoItem2 demoItem" id="demoItem2">IE瀏覽器內(nèi)容</div>
<div class="demoItem3 demoItem" id="demoItem3">火狐瀏覽器內(nèi)容</div>
<div class="demoItem4 demoItem" id="demoItem4">360瀏覽器內(nèi)容</div>
<div class="demoItem5 demoItem" id="demoItem5">獵豹瀏覽器內(nèi)容</div>
</div>
</div>
</template><script>
// 引入
var VueScrollTo = require("vue-scrollto");
export default {
data() {
return {
idx: 0,
demoNavItem: [
"谷歌瀏覽器",
"uc瀏覽器",
"IE瀏覽器",
"火狐瀏覽器",
"360瀏覽器",
"獵豹瀏覽器",
],
};
},
methods: {
// 導(dǎo)航選中效果
changNav(index) {
this.idx = index;
VueScrollTo.scrollTo(document.getElementById("demoItem" + index), 1000, {
offset: -50,
});
},
},
};
</script><style scoped>
.flex-center-center {
display: flex;
align-items: center;
justify-content: center;
}
.demoNav {
width: 100%;
height: 70px;
background: rgba(0, 31, 144, 1);
position: sticky;
left: 0;
top: 0;
}
.demoNavItem {
font-size: 40px;
color: #fff;
margin-left: 30px;
cursor: pointer;
}
.navActive {
color: red;
}
.demoItem {
width: 100%;
height: 600px;
font-size: 60px;
color: #fff;
text-align: center;
padding: 60px 0 0 0;
}
.demoItem0{
background: gold;
}
.demoItem1 {
background: red;
}
.demoItem2 {
background: chartreuse;
}
.demoItem3 {
background: cornflowerblue;
}
.demoItem4 {
background: cyan;
}
.demoItem5 {
background: darkmagenta;
}
</style>效果圖:

總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Vue項(xiàng)目中實(shí)現(xiàn)描點(diǎn)跳轉(zhuǎn)scrollIntoView的案例
- Vue結(jié)合ElementUI實(shí)現(xiàn)數(shù)據(jù)請(qǐng)求和頁(yè)面跳轉(zhuǎn)功能(最新推薦)
- vue跳轉(zhuǎn)時(shí)根據(jù)url錨點(diǎn)(#xxx)實(shí)現(xiàn)頁(yè)面內(nèi)容定位的方法
- Vue通過(guò)vue-router實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的全過(guò)程
- Vue.js頁(yè)面驗(yàn)證跳轉(zhuǎn)功能實(shí)現(xiàn)
相關(guān)文章
vue報(bào)錯(cuò)Not?allowed?to?load?local?resource的解決辦法
這篇文章主要給大家介紹了關(guān)于vue報(bào)錯(cuò)Not?allowed?to?load?local?resource的解決辦法,這個(gè)錯(cuò)誤是因?yàn)閂ue不能加載本地資源的原因,需要的朋友可以參考下2023-07-07
一篇看懂vuejs的狀態(tài)管理神器 vuex狀態(tài)管理模式
一篇看懂vuejs的狀態(tài)管理神器,Vuex一個(gè)專為Vue.js應(yīng)用程序開(kāi)發(fā)的狀態(tài)管理模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
Vue利用相反數(shù)實(shí)現(xiàn)飄窗動(dòng)畫效果
飄窗,即一個(gè)類似小窗子的在網(wǎng)頁(yè)上移動(dòng)的矩形元素,通常被用于一些通知類的應(yīng)用場(chǎng)景。本文將利用相反數(shù)實(shí)現(xiàn)這一動(dòng)畫效果,需要的可以參考一下2022-05-05
vue項(xiàng)目build打包后部分樣式錯(cuò)亂的解決
這篇文章主要介紹了vue項(xiàng)目build打包后部分樣式錯(cuò)亂的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07

