javascript - 我的滚动到顶部不流畅
问题描述
这是我的代码:
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
解决方案
推荐阅读
- azure-service-fabric - 为 Service Fabric 本地群集启用 ResourceMonitorService 插件失败
- awk - 用 awk 替换大写或小写的字符串
- json - Ionic App 在 Android 设备上无法正常工作
- apache-kafka - 为什么这个 KStream/KTable 拓扑会传播未通过过滤器的记录?
- javascript - .diff 不是 Moment.js 中的函数
- c# - 通过 Twilio C# 库发出呼叫或短信请求是否总是使用 HTTPS?
- powershell - 检查 PowerShell SecureString 是否有值
- javascript - express + pug 应用程序,当 txt 文件更改时更新多条路线?
- javascript - 构建搜索应用程序时,什么最有效:search:search 或 cts:search?
- azure - Cloud_RoleName 通过 ILogger 不一致地获取值