SOURCE

console 命令行工具 X clear

                    
>
console
var obj = document.getElementById("wrap");
var ot = obj.offsetTop;
document.onscroll = function () {
    var st = document.body.scrollTop || document.documentElement.scrollTop;
    obj.setAttribute("data-fixed",st >= ot?"fixed":"")
}
<div id="wrap"></div>
*{
	margin: 0;
	padding: 0;
}
body{
	height: 2000px;
	background-image: linear-gradient(-180deg, #15f09d 0%, #25A0FF 50%, #fca72b 100%);
}
#wrap{
	background-color: rgba(0,0,0,0.2);
	width: 100%;
	height: 100px;
	margin-top: 100px;
}
#wrap[data-fixed="fixed"]{
	position: fixed;
	top:0;
	left: 0;
	margin: 0;
}