我想在滚动时使用固定元素更改正文的背景颜色。
body {
margin: 0;
background: lightblue;
}
.blue-container {
height: 70vh;
}
.blue {
height: 40vh;
position: sticky;
width: 70%;
top: 0;
background: blue;
margin: auto;
}
.pink {
height: 500px;
position: relative;
width: 70%;
margin-right: auto;
margin-left: auto;
background: pink;
text-align: center;
}
<div class='blue-container'>
<div class='blue'></div>
</div>
<div class='pink'> When I touch the blue bloc, I would like the 'body background' change into an other color (for exemple : orange)</div>
这是我用来理解我的需求的jsFiddle。