Certainly! A sticky header is a common feature in web design that remains fixed at the top of the page as the user scrolls down. Here's a basic example using HTML, CSS, and JavaScript:
HTML:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Sticky Header Example</title>
</head>
<body>
<header id="sticky-header">
<h1>Your Website</h1>
</header>
<!-- Rest of your website content goes here -->
<script src="script.js"></script>
</body>
</html>
```
CSS (styles.css):
```css
body {
margin: 0;
font-family: 'Arial', sans-serif;
}
header {
background-color: #333;
color: #fff;
padding: 15px;
text-align: center;
}
/* Add styles for the rest of your content here */
.sticky {
position: fixed;
top: 0;
width: 100%;
animation: slideDown 0.5s;
}
@keyframes slideDown {
from {
transform: translateY(-100%);
}
to {
transform: translateY(0);
}
}
```
JavaScript (script.js):
```javascript
window.onscroll = function() {
stickyHeader();
};
const header = document.getElementById("sticky-header");
const sticky = header.offsetTop;
function stickyHeader() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
```
In this example, when the user scrolls down the page, the `stickyHeader` function is called, which adds the class "sticky" to the header when the scroll position reaches a certain point (`sticky`). The sticky class is defined in CSS to make the header fixed at the top of the page. The animation is optional and provides a smooth transition when the header becomes sticky. Adjust styles and animations according to your design preferences.
4.9/5 (93 votes)
Có thể bạn quan tâm:
Lãi suất Vay tiền bằng CMND online luôn dưới 20%/năm và phù hợp với quy định của nhà nước. Mức lãi suất này tương đối thấp so với vay nóng bên ngoài. Ngay cả khi chưa có khả năng trả nợ đúng hạn thì Vay tiền bằng CMND trực tuyến cũng rất an toàn.
Vay tiền bằng CMND online có thủ tục đơn giản, giải ngân chuyển khoản ngay trong ngày, đăng ký Vay tiền bằng CMND trực tuyến không cần giấy tờ, không cần gặp mặt, được hỗ trợ lãi suất 0% lần đầu.
Hiện nay có rất nhiều công ty tài chính hỗ trợ Vay tiền bằng CMND online uy tín nhưng không phải ai cũng biết. Chúng tôi có liệt kê danh sách các đơn vị hỗ trợ Vay tiền bằng CMND trực tuyến ưu đãi 0% lãi suất lần đầu ở trong bài hoặc tại link website Vaytiengopthang.com
Vay tiền bằng CMND online rất đơn giản, chỉ mất 5 phút đăng ký Vay tiền bằng CMND trực tuyến là nhận được tiền, không cần gặp mặt, không cần giấy tờ gốc. Đăng ký Vay tiền bằng CMND qua mạng tại danh sách link liệt kê trong bài hoặc xem tại web Vaytiengopthang.com