<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>滚动换色</title>
<style type="text/css">
body {
height: 5000px;
transition:all 1s linear 0s;
}
</style>
</head>
<body>
<script type="text/javascript">
var b = document.body;
b.onscroll = function(){
console.log(b.scrollTop)
if(b.scrollTop >= 300 && b.scrollTop <= 1000){
b.style.background = "red";
}
else if(b.scrollTop > 1000 && b.scrollTop <= 3000){
b.style.background = "green";
}
else{
b.style.background = "blue";
}
}
</script>
</body>
</html>