vue3 Element-Plus el-backtop無效問題及解決
vue3 Element-Plus el-backtop無效
基本格式:
<template> <div class="box"> <el-backtop target=".box" :visibility-height="100" :bottom="60" :right="20"></el-backtop> <div> 頁面........ </div> </div> </template>
有時(shí)候會(huì)發(fā)現(xiàn)這個(gè)根本無效,那么父級(jí)盒子最好設(shè)置以下樣式
height: 100%; // 不必是100vh,只需要是該容器顯示的最大高度即可 overflow-x: hidden;
element Backtop 回到頂部簡單使用
visibility-height:滾動(dòng)高度達(dá)到此參數(shù)值才出現(xiàn),默認(rèn)200,是number類型(使用如:visibility-height="100")
target
:觸發(fā)滾動(dòng)的對(duì)象,是String類型,你可以不傳right
:控制其顯示位置, 距離頁面右邊距,默認(rèn)40,是number類型,數(shù)值越大,離右邊越遠(yuǎn)。bottom
:控制其顯示位置, 距離頁面底部距離。默認(rèn)40,是number類型,你可以調(diào)整他的值,越大離底部越遠(yuǎn)。
直接貼代碼 拿去piao
//默認(rèn)的 我們可以什么都不傳,調(diào)用這個(gè)組件即可使用。 <el-backtop></el-backtop> //設(shè)置底部距離的 <el-backtop :bottom="60"> </el-backtop> //帶文字的 <el-backtop :bottom="60"> <div style="{ height: 100%; width: 100%; background-color: #f2f5f6; box-shadow: 0 0 6px rgba(0,0,0, .12); text-align: center; line-height: 40px; color: #1989fa; }" > top </div> </el-backtop>
引用了element 直接使用就行!
vue原生回到頂部
<template> <div class=""> <transition> <div class="gotop-index" v-show="btnFlag"> <a href="javascript:;" rel="external nofollow" class="gotop-a" @click="backTop"></a> </div> </transition> </div> </template> <script> export default { data() { return { btnFlag: false } }, mounted() { // 此處true需要加上,不加滾動(dòng)事件可能綁定不成功 window.addEventListener("scroll", this.scrollToTop, true); }, destroyed() { window.removeEventListener("scroll", this.scrollToTop, true); }, methods:{ backTop() { const that = this; let timer = setInterval(() => { let ispeed = Math.floor(-that.scrollTop / 5); document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed; if (that.scrollTop === 0) { clearInterval(timer); } }, 16); }, // 為了計(jì)算距離頂部的高度,當(dāng)高度大于60顯示回頂部圖標(biāo),小于60則隱藏 scrollToTop() { console.log(123); const that = this; let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; that.scrollTop = scrollTop; if (that.scrollTop > 30) { that.btnFlag = true; } else { that.btnFlag = false; } }, }, } </script> <style lang="css" scoped> .wrap_box{ } /*返回頂部*/ .gotop-index { position: fixed; right: 0.6rem; bottom: 1.6rem; display: block; width: 0.8rem; height: 0.8rem; background: #fff; box-shadow: 0px 0px 4px #ff0000; display: flex; border-radius: 50%; z-index: 999; } .gotop-a { display: block; width: 0.5rem; height: 0.5rem; background: url(~@/assets/images/icon-top.gif) no-repeat 0 0; background-size: 0.5rem; margin: auto; } </style>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用van-picker?動(dòng)態(tài)設(shè)置當(dāng)前選中項(xiàng)
這篇文章主要介紹了使用van-picker?動(dòng)態(tài)設(shè)置當(dāng)前選中項(xiàng)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10Vue在自定義指令綁定的處理函數(shù)中傳遞參數(shù)
這篇文章主要介紹了Vue在自定義指令綁定的處理函數(shù)中傳遞參數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03vue頁面跳轉(zhuǎn)實(shí)現(xiàn)頁面緩存操作
這篇文章主要介紹了vue頁面跳轉(zhuǎn)實(shí)現(xiàn)頁面緩存操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07在vue2項(xiàng)目中使用dart-sass的問題及解決方法
在Vue2項(xiàng)目中,使用dart-sass替代node-sass可以解決安裝困難和環(huán)境兼容問題,VueCLI3+用戶可直接使用,而VueCLI2用戶需升級(jí)VueCLI和項(xiàng)目,具體方法包括修改package.json依賴并使用.scss文件編寫樣式,此更改有助于提升項(xiàng)目的開發(fā)效率和跨平臺(tái)兼容性2024-09-09詳解Vuejs2.0 如何利用proxyTable實(shí)現(xiàn)跨域請(qǐng)求
本篇文章主要介紹了Vuejs2.0 如何利用proxyTable實(shí)現(xiàn)跨域請(qǐng)求,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08