vue3 Element-Plus el-backtop無(wú)效問題及解決
vue3 Element-Plus el-backtop無(wú)效
基本格式:
<template> <div class="box"> <el-backtop target=".box" :visibility-height="100" :bottom="60" :right="20"></el-backtop> <div> 頁(yè)面........ </div> </div> </template>
有時(shí)候會(huì)發(fā)現(xiàn)這個(gè)根本無(wú)效,那么父級(jí)盒子最好設(shè)置以下樣式
height: 100%; // 不必是100vh,只需要是該容器顯示的最大高度即可 overflow-x: hidden;
element Backtop 回到頂部簡(jiǎn)單使用
visibility-height:滾動(dòng)高度達(dá)到此參數(shù)值才出現(xiàn),默認(rèn)200,是number類型(使用如:visibility-height="100")
target:觸發(fā)滾動(dòng)的對(duì)象,是String類型,你可以不傳right:控制其顯示位置, 距離頁(yè)面右邊距,默認(rèn)40,是number類型,數(shù)值越大,離右邊越遠(yuǎn)。bottom:控制其顯示位置, 距離頁(yè)面底部距離。默認(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è)參考,也希望大家多多支持腳本之家。
- vue3使用Element-plus的el-pagination分頁(yè)組件時(shí)無(wú)法顯示中文
- 關(guān)于Vue3中element-plus的el-dialog對(duì)話框無(wú)法顯示的問題及解決方法
- Vue3如何解決Element-plus不生效的問題
- vue3配置Element及element-plus/lib/theme-chalk/index.css報(bào)錯(cuò)的解決
- vue3 element-plus如何使用icon圖標(biāo)組件
- vue3 element-plus el-tree自定義圖標(biāo)方式
- vue3無(wú)法顯示element-plus問題及解決
相關(guān)文章
基于vue+face-api.js實(shí)現(xiàn)前端人臉識(shí)別功能
基于face-api.js要實(shí)現(xiàn)人臉識(shí)別功能,首先要將自己需要的模型文件下載保存在靜態(tài)目錄下,可以通過(guò)cdn的方式在index.html中引入face-api.js,本文給大家介紹vue+face-api.js實(shí)現(xiàn)前端人臉識(shí)別功能,感興趣的朋友一起看看吧2023-12-12
vue設(shè)置動(dòng)態(tài)請(qǐng)求地址的例子
今天小編就為大家分享一篇vue設(shè)置動(dòng)態(tài)請(qǐng)求地址的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11
Vue實(shí)現(xiàn)簡(jiǎn)易購(gòu)物車案例
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)簡(jiǎn)易購(gòu)物車案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06
Vue3實(shí)現(xiàn)自定義指令攔截點(diǎn)擊事件的示例代碼
某些應(yīng)用場(chǎng)景會(huì)給點(diǎn)擊事件添加權(quán)限,不存在權(quán)限就攔截點(diǎn)擊事件,有權(quán)限就繼續(xù)正常觸發(fā)點(diǎn)擊事件。這樣的效果是如何實(shí)現(xiàn)的呢,本文就來(lái)和大家詳細(xì)講講2023-02-02
vue3的setup語(yǔ)法如何自定義v-model為公用hooks
這篇文章主要介紹了vue3的setup語(yǔ)法如何自定義v-model為公用hooks,文章分為兩個(gè)部分介紹,簡(jiǎn)單介紹vue3的setup語(yǔ)法如何自定義v-model和如何提取v-model語(yǔ)法作為一個(gè)公用hooks2022-07-07

