李成 4 months ago
parent 02df881da6
commit 15ce73bb9f

File diff suppressed because one or more lines are too long

@ -1,11 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="ProgressBar"></div>
<div class="header">
我是头部
</div>
@ -15,7 +18,8 @@
</div>
</div>
<!--回到顶部按钮-->
<div id="toTop" style="position: fixed; bottom: 70px; right: 50px; border-radius: 50%; background-color: rgba(0,0,0,0.1); height: 30px;width: 30px; display: none;flex-direction: column; justify-content: center; align-items: center;">
<div id="toTop"
style="position: fixed; bottom: 70px; right: 50px; border-radius: 50%; background-color: rgba(0,0,0,0.1); height: 30px;width: 30px; display: none;flex-direction: column; justify-content: center; align-items: center;">
<img src="./assets/top.png" style="height: 20px; width: 20px;" alt="">
</div>
</body>
@ -33,22 +37,42 @@
font-size: 30px;
transition: all 0.3s;
}
.main {
height: 1800px;
width: 1000px;
background-color: pink;
}
.content {
position: absolute;
top: 500px;
background-color: gray;
}
.ProgressBar {
height: 3px;
width: 0vw;
background-color: rgb(12, 128, 236);
position: fixed;
top: 0px;
z-index: 100;
}
</style>
<script src="./jquery-3.7.1.min.js"></script>
<script>
const content = document.querySelector('.content')
const header = document.querySelector('.header')
const toTop = document.querySelector('#toTop')
const ProgressBar = $(".ProgressBar")
$(window).scroll(function (e) {
let scrollTop = $(window).scrollTop(); // 获取滚动条的位置
let docHeight = $(document).height(); // 获取文档的高度
let windowHeight = $(window).height(); // 获取窗口的高度
let scrollProgress = (scrollTop) / (docHeight - windowHeight); // 计算滚动进度
ProgressBar.width(scrollProgress * 100 + 'vw'); // 设置进度条宽度
})
window.addEventListener('scroll', function () {
const n = document.documentElement.scrollTop
let viewScrollTop = document.documentElement.scrollTop
@ -69,4 +93,5 @@
})
</script>
</html>
Loading…
Cancel
Save