当前位置:网站首页>Click the button to return to the top smoothly
Click the button to return to the top smoothly
2022-07-24 20:06:00 【So Lanxun】
Preface
In the development process , There must be operations that need to return to the top , Many people will go straight back to the top , It's like jumping , Greatly reduced the experience , The following code can make your return top become silky .
Realization
Whether it's original or not , still vue、react, This method is applicable , Directly copy it into the method
// To the top completion time 0.5 second
let finished_time = 500;
// Every time 0.01 Move upward once every second
let interval_time = 10;
// The distance from the current position to the top
let scrollTop = window.pageYOffset;
// Calculate how many pixels to slide up each interval
let top_pixel = scrollTop / finished_time * interval_time;
// Slide the interval upward through the timer
let timer = setInterval(() => {
scrollTop -= top_pixel;
// It's a negative number , The browser will not handle
window.scrollTo(0, scrollTop);
if (scrollTop <= 0) {
clearInterval(timer)
}
}, interval_time)
边栏推荐
- Solve the problem of error l6218e undefined symbol XXX
- 870. Approximate number
- 【LeetCode】1184. 公交站间的距离
- Cmake series tutorial 2 HelloWorld
- Unity3d eventsystem (event)
- 英文翻译中文常见脏话
- MySQL stored procedure
- Anaconda installs labelimg (super simple and available)
- [trial experience of Yuxin micro Wiota ad hoc network protocol development kit] RT thread BSP Software package production
- The beginning of winter in the year of bitterness and ugliness
猜你喜欢

从码农转型大音乐家,你只差这些音乐处理工具

Look at the interface control devaxpress WinForms - how to customize auxiliary function properties (Part 2)

Usage and introduction of MySQL binlog

Interface component devaxpress asp Net v22.1 - new office 365 dark theme

Common methods of string class

Batch download files from the server to the local

Richview table table alignment

147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用

【德味】安全:如何为行人提供更多保护

Setting up a dual machine debugging environment for drive development (vs2017)
随机推荐
Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)
day 2
Decorator of function
Sword finger offer 46. translate numbers into strings
Thymeleaf application notes
MySQL advanced
Introduction to fastdfs high availability
[face to face experience of school recruitment] 8 real questions of pointer interview. Come and test how many you have mastered.
Virbox compiler, which supports source code encryption of the whole platform and architecture
Connect the smart WiFi remote control in the home assistant
Wechat applet -that.setdata ({}) set complex field data
Classic interview questions of interface testing: what is the difference between session, cookie and token?
The beginning of winter in the year of bitterness and ugliness
Sword finger offer 52. The first common node of the two linked lists
Prevent static decompilation, dynamic debugging and plug-in
Solutions to oom caused by pictures in res directory
Detailed explanation of ELF format (I)
MySQL advanced 2
Read the registry through the ATL library clegkey (simple and convenient)
Call Baidu AI open platform to realize image and character recognition