first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>淘宝头部定位</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
height: 3000px;
}
.head {
width: 100%;
height: 60px;
}
.head_menu {
width: 100%;
height: 50px;
background: #e3bcbc;
/* margin: 0 auto; */
}
</style>
</head>
<body>
<div class="head"> </div>
<div class="head_menu"></div>
</body>
<script>
// 给网页绑定滚动事件
// 获取滚动条的滚动距离,然后拿滚动距离进行判断 document.documentElement.scrollTop
// 大于 某个数值 ,给 html 定固定定位,反之不加
var body = $("body"), head_menu = $(".head_menu");
body.onscroll = () => {
var offsetTop = document.documentElement.scrollTop;
// console.log("offsetTop: ", offsetTop);
if(offsetTop >60 ){
head_menu.style.position = "fixed"
head_menu.style.top = "0"
}else{
head_menu.style.position = "static"
}
}
function $(className) {
return document.querySelector(className);
}
function _(className) {
return document.querySelectorAll(className);
}
</script>
</html>