Effect: Code: <template> <div class="back-top"> <div > <img src="imgsrc" class="line" :class="isHide? 'isHide': 'isShow'" :style="{display: (firstShow? 'block': 'none')}" @click="backTop"> </div> </div> </template> <script> export default { name: "backTop", data(){ return { firstShow: false, //Initialize hidden components isHide: false, scrollFLag: true, } }, created() { document.addEventListener('scroll', () => { let scroll = document.documentElement.scrollTop if(scroll > 200){ this.isHide = false this.firstShow = true }else{ this.isHide = true } }) }, methods: { backTop(){ if(this.scrollFLag){ this.scrollFLag = false //Screen height let scroll = document.documentElement.scrollTop let scrollTimer = setInterval(()=> { scroll -= 50 document.documentElement.scrollTop = Math.max(scroll, 0) if( scroll <= 0){ clearInterval(scrollTimer) } }, 10) this.scrollFLag = true } }, }, } </script> <style scoped lang="scss"> .back-top{ position: fixed; top: 0; right: 10vw; width: 20px; height: 500px; z-index: 200; .line{ width: 12vw; height: 100%; z-index: 20; cursor: pointer; opacity: 0.8; transform: translateY(-100%); &:hover{ opacity: 1; } } .isShow{ animation: back-top-move 0.5s forwards linear, back-top-yurayura 2s 0.6s forwards linear infinite; } .isHide{ animation: back-top-hide 0.5s forwards linear; } } @keyframes back-top-hide { from { transform: translateY(0); } to { transform: translateY(-100%); } } @keyframes back-top-move { to { transform: translateY(0); } } @keyframes back-top-yurayura { 0%{transform-origin: top center;transform: rotate(0)} 25%{transform-origin: top center;transform: rotate(2deg)} 75%{transform-origin: top center;transform: rotate(-2deg)} 100%{transform-origin: top center;transform: rotate(0)} } </style> This is the end of this article about the complete code implementation of the vue backtop component. For more related vue backtop component content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Mysql Sql statement comments
>>: Detailed explanation of redis persistence, master-slave synchronization and sentinel under Linux
This article records the detailed tutorial of MyS...
A jQuery plugin every day - to make search histor...
This question is very strange, so I will go strai...
Table of contents What is a listener in vue Usage...
Table of contents Overview 1. Compositon API 1. W...
The solution to the problem that mysql cannot be ...
1. Find the corresponding nodejs package, refer t...
Table of contents Parent component listBox List c...
Table of contents WXS Response Event Plan A Page ...
A major feature of the WeChat 8.0 update is the s...
Problem description: When inserting Chinese chara...
The role of the a tag pseudo-class: ":link&qu...
About JS, CSS CSS: Stylesheet at the top Avoid CS...
Add table fields alter table table1 add transacto...
1. Enter the configuration file of the yum source...