vue關(guān)于錨點定位、跳轉(zhuǎn)到指定位置實現(xiàn)方式
更新時間:2024年04月28日 08:55:41 作者:皮卡丘是個程序猿
這篇文章主要介紹了vue關(guān)于錨點定位、跳轉(zhuǎn)到指定位置實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
vue錨點定位、跳轉(zhuǎn)到指定位置
直接上代碼
<template> <div> <nav class="nav"> <button @click="go('#m1')">昨天</button> <button @click="go('#m2')">今天</button> <button @click="go('#m3')">明天</button> </nav> <div style="height: 50px;"></div> <div id="m1"> <h1>昨天</h1> <div v-for="item in 50">昨天</div> </div> <div id="m2"> <h1>今天</h1> <div v-for="item in 50">今天</div> </div> <div id="m3"> <h1>明天</h1> <div v-for="item in 50">明天</div> </div> </div> </template> <script> export default { data() { return {}; }, methods: { go(selector) { document.querySelector(selector).scrollIntoView({ // 不想要滾動動畫,則設(shè)置為"instant" behavior: 'smooth', // 滾動動畫 block: 'center' }); } } }; </script> <style scoped> .nav { text-align: center; position: fixed; top: 0px; width: 100%; height: 50px; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); background: #fff; } </style>
vue中錨點定位scrollIntoView
<el-card class="maodian"> <div slot="header" class="clearfix"> <span>maodian</span> </div> </el-card> <el-button type="text" @click="handleJump('.maodian')" >maodian</el-button> Jump(val) { const dom = document.querySelector(val); if (dom) { dom.scrollIntoView(true); } },
使用element.scrollIntoView跳轉(zhuǎn)
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vux+Axios攔截器增加loading的問題及實現(xiàn)方法
這篇文章主要介紹了Vux+Axios攔截器增加loading的問題及實現(xiàn)方法,文中通過實例代碼介紹了vue中使用axios的相關(guān)知識,需要的朋友可以參考下2018-11-11vue3+element?Plus實現(xiàn)表格前端分頁完整示例
這篇文章主要給大家介紹了關(guān)于vue3+element?Plus實現(xiàn)表格前端分頁的相關(guān)資料,雖然很多時候后端會把分頁,搜索,排序都做好,但是有些返回數(shù)據(jù)并不多的頁面,或者其他原因不能后端分頁的通常會前端處理,需要的朋友可以參考下2023-08-08解決vue項目運行提示W(wǎng)arnings while compiling.警告的問題
這篇文章主要介紹了解決vue項目運行提示W(wǎng)arnings while compiling.警告的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09