<>固定在界面右侧的“回到顶部”按钮

<>首先要给需要定位的元素一个id,后续根据id跳转,不管是回到顶部还是定位到界面任意位置,都是根据id来定位。

<>其次给需要触发定位的元素加上点击事件toPage(index),这个index参数直接写好,比如0就是定位到顶部,1就是定位到其他我想定位的位置…
<div class="top" @click="toPage(0)">TOP</div> methods: { // 定位 toPage(index) {
if (index == 0) { // cover是我最外层元素的id document.getElementById("cover").
scrollIntoView({ behavior: "smooth" }); } if (index == 1) { //
face是我想要定位的其他位置元素id document.getElementById("face").scrollIntoView({ behavior:
"smooth" }); } }, }, .top { position: fixed; right: 0; bottom: 50%; z-index:
99999; width: 95px; height: 95px; background-color: #0180bc; }

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:766591547
关注微信