Cách tạo: ký hiệu cuộn
- Trang trước Chtimeline
- Trang tiếp theo Đường tiến độ
Học cách sử dụng CSS và JavaScript để tạo ký hiệu cuộn.
Cách tạo ký hiệu cuộn
Bước 1 - Thêm HTML:
<div class="header"> <h2>ký hiệu cuộn</h2> <div class="progress-container"> <div class="progress-bar" id="myBar"></div> </div> </div> <div>content...</div>
Bước 2 - Thêm CSS:
/* Đặt樣式 tiêu đề: vị trí cố định (luôn保持在頂部) */ .header { position: fixed; top: 0; z-index: 1; width: 100%; background-color: #f1f1f1; } /* Hộp tiến độ (màu nền xám) */ .progress-container { width: 100%; height: 8px; background: #ccc; } /* Thanh tiến độ (ký hiệu cuộn) */ .progress-bar { height: 8px; background: #04AA6D; width: 0%; }
Bước 3 - Thêm JavaScript:
// Khi người dùng cuộn trang, thực hiện myFunction window.onscroll = function() {myFunction()}; function myFunction() { var winScroll = document.body.scrollTop || document.documentElement.scrollTop; var height = document.documentElement.scrollHeight - document.documentElement.clientHeight; var scrolled = (winScroll / height) * 100; document.getElementById("myBar").style.width = scrolled + "%"; }
- Trang trước Chtimeline
- Trang tiếp theo Đường tiến độ