要实现一个顶部的线性加载进度条,您可以使用以下代码示例作为参考:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#progress-bar {
position: fixed;
top: 0;
left: 0;
height: 2px;
width: 0;
background-color: #b91f1f;
transition: width 0.3s;
}
</style>
</head>
<body>
<div id="progress-bar"></div>
<!-- 页面内容 -->
<h1>Welcome to my website</h1>
<p>This is some content...</p>
<script>
window.addEventListener('load', function() {
const progressBar = document.getElementById('progress-bar');
progressBar.style.width = '100%';
setTimeout(function() {
progressBar.style.dis