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
1. Installation apt-get install mysql-server requ...
Table of contents Linux netstat command 1. Detail...
There are two ways to disable form submission in ...
In MySQL, database garbled characters can general...
Preface: Use debugbar to view document code in iet...
Table of contents 1. Create a stored function 2. ...
This article example shares the specific code of ...
A set of MySQL libraries for testing. The previou...
This article summarizes the knowledge points of M...
Single page application characteristics "Ass...
Table of contents react-native project initializa...
Table of contents JS reads file FileReader docume...
This article uses an example to illustrate how to...
This article shares the specific process of js ob...
Idea: Just sort randomly first and then group. 1....