Vue實現(xiàn)回到頂部和底部動畫效果
更新時間:2019年07月31日 16:03:11 作者:zzh1918
這篇文章主要為大家詳細介紹了Vue實現(xiàn)回到頂部和底部動畫效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Vue實現(xiàn)回到頂部和底部動畫效果的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
<template> <div> <div class="scroll" :class="{show:isActive}"> <div id="toTop" @click="toTop(step)"><</div> <div id="toBottom" @click="toBottom(step)">></div> </div> </div> </template> <script> export default{ props:{ step:{ //此數(shù)據(jù)是控制動畫快慢的 type:Number, default:50 } }, data(){ return { isActive:false, } }, methods:{ toTop(i){ //參數(shù)i表示間隔的幅度大小,以此來控制速度 document.documentElement.scrollTop-=i; if (document.documentElement.scrollTop>0) { var c=setTimeout(()=>this.toTop(i),16); }else { clearTimeout(c); } }, toBottom(i){ var clientHeight=document.documentElement.clientHeight||document.body.clientHeight; var scrollHeight=document.documentElement.scrollHeight; var height=scrollHeight-clientHeight; //超出窗口上界的值就是底部的scrolTop的值 document.documentElement.scrollTop+=i; if (document.documentElement.scrollTop<height) { var c=setTimeout(()=>this.toBottom(i),16); }else { clearTimeout(c); } } }, created(){ var vm=this; window.οnscrοll=function(){ if (document.documentElement.scrollTop>60) { vm.isActive=true; }else { vm.isActive=false; } } } } </script> <style scoped> .scroll{ position: fixed; right: 10px; bottom: 60px; width: 45px; height: 90px; cursor: pointer; display: none; } .scroll>div{ width: 45px; height: 45px; transform: rotate(90deg); line-height: 45px; text-align: center; font-size: 35px; font-family: "黑體"; background-color: rgba(0,0,0,.2); color: #fff; } .scroll>div:hover{ background-color: rgba(0,0,0,.5); } .show{ display: block; } </style>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue2 如何實現(xiàn)div contenteditable=“true”(類似于v-model)的效果
這篇文章主要給大家介紹了利用vue2如何實現(xiàn)div contenteditable="true",就是類似于v-model的效果,文中給出了兩種解決的思路,對大家具有一定的參考價值,有需要的朋友們下面來一起看看吧。2017-02-02詳解vue中v-for和v-if一起使用的替代方法template
這篇文章主要介紹了vue中v-for和v-if一起使用的替代方法template,使用的版本是vue?2.9.6和element-ui:?2.15.6,通過實例代碼給大家講解的非常詳細,需要的朋友可以參考下2022-05-05Vue中使用jsencrypt進行RSA非對稱加密的操作方法
這篇文章主要介紹了Vue中使用jsencrypt進行RSA非對稱加密,在這里需要注意要加密的數(shù)據(jù)必須是字符串,對Vue?RSA非對稱加密相關(guān)知識感興趣的朋友一起看看吧2022-04-04Vue+tracking.js 實現(xiàn)前端人臉檢測功能
這篇文章主要介紹了Vue+tracking.js 實現(xiàn)前端人臉檢測功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04