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è)面問題,具有很好的參考價(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è)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
vue項(xiàng)目打包發(fā)布到Nginx后無(wú)法訪問后端接口的解決辦法
這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目打包發(fā)布到Nginx后無(wú)法訪問后端接口的解決辦法,記錄一下項(xiàng)目需要注意的地方,方便以后快速使用,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04Vue項(xiàng)目中ESlint規(guī)范示例代碼
這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中ESlint規(guī)范的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07vue實(shí)現(xiàn)頁(yè)面div盒子拖拽排序功能
本文主要介紹了vue實(shí)現(xiàn)頁(yè)面div盒子拖拽排序功能,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10vue項(xiàng)目中axios請(qǐng)求網(wǎng)絡(luò)接口封裝的示例代碼
這篇文章主要介紹了vue項(xiàng)目中axios請(qǐng)求網(wǎng)絡(luò)接口封裝的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2018-12-12vue計(jì)算屬性computed方法內(nèi)傳參方式
這篇文章主要介紹了vue計(jì)算屬性computed方法內(nèi)傳參方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10一文詳解Vue中如何實(shí)現(xiàn)頁(yè)面骨架屏
為了提升頁(yè)面加載速度,我們可以使用頁(yè)面骨架屏技術(shù)來(lái)優(yōu)化用戶感知,下面就跟隨小編一起學(xué)習(xí)一下如何在vue中實(shí)現(xiàn)頁(yè)面骨架屏吧2024-03-03