<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<style type="text/css">
body {
margin: 0;
}
#demo {
position: sticky;
top: 0;
height: 100px;
padding-top: 1rem;
padding-bottom: 1rem;
background-color: #E6E6E6;
border-top: 15px solid blue;
}
</style>
<nav id="demo">
导航条
</nav>
<div style="height: 300vh;">
123
</div>
456
</body>
</html>
需求
给定一个位置(随便什么位置都行)
当滚动条超出这个位置时(在这个位置的下面)
将上面导航条上下外边距设置为0, 边框设置为0
当滚动条未超出这个位置时(在这个位置的上面)
返回原先的样式(上下边距1rem, 边框15px, 蓝色)
如何使用js或jquery动画效果实现?
已解决
使用 IntersectionObserver 和 $.animate()