<div class="totop" v-show="toTopShow" @click="toTop()">top</div>
.totop { width: 50px; height: 50px; line-height: 50px; border-radius: 25px; background-color: white; position: fixed; bottom: 75px; right: 10px; text-align: center; }
data() { return { toTopShow: false, srcoll: 0, } },
watch: srcoll() { if (this.srcoll > 400) { this.toTopShow = true; } else { this.toTopShow = false; } }, },
mounted() { window.addEventListener("scroll", this.srcollShow); },
methods: { srcollShow() { this.srcoll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; }, toTop() { this.toTopSpeed = setInterval(() => { document.documentElement.scrollTop = document.documentElement.scrollTop - 20; //Delayed scrolling animation by changing numbers if (this.srcoll < 10) { clearInterval(this.toTopSpeed); } }, 1); }, } The above operation is achieved by monitoring the scroll bar > 400, the top button appears, and click the top button to slowly return to the top, below 400 hide, img and so on This is the end of this article about how to use v-show to achieve the top effect in vue. For more relevant vue back to the top effect content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: HTML left, center, right adaptive layout (using calc css expression)
>>: MySQL practical window function SQL analysis class students' test scores and living expenses
Table of contents Simple Factory Factory Method S...
Achieve resultsImplementation Code html <heade...
<br />Original text: http://research.microso...
Table of contents Overview Static type checking C...
Upgrade background: In order to solve the vulnera...
What is a mata tag The <meta> element provi...
Two parameters of Mysql paging select * from user...
Table of contents Background 1. What is dns-prefe...
This article will introduce how to query data in ...
I have been having this problem recently when desi...
background Since I was assigned to a new project ...
Practice is the only way to test the truth. This ...
This article uses examples to describe the basic ...
1. Create a user: Order: CREATE USER 'usernam...
Sample code: import java.util.Random; import java...