CSS - 根据背景更改文本颜色

fig*_*r20 2 html css jquery

我有一个简单的布局,包括三个全高div和一个固定的标题栏.

body,html {
  padding:0;
  margin:0;
}

.header {
  position:fixed;
  width:100%;
  height:50px;
  color:white;
  margin:20px;
}

.section1 {
  background:black;
  height:100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color:white;
}

.section2 {
  background:white;
  height:100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.section3 {
  background:black;
  height:100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color:white;
}
Run Code Online (Sandbox Code Playgroud)
<div class="header">
  Header Content
</div>
<div class="wrapper">
  <div class="section1">
    Section One Content
  </div>
  <div class="section2">
    Section Two Content
  </div>
  <div class="section3">
    Section Three Content
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我试图使标题栏文本颜色更改为黑色,当它滚动具有白色背景的部分.

我已经看到了几个jQuery插件应该可以实现这一点,但我试图避免任何不必要的脚本.

CSS mix-blend-mode功能是否允许我实现这一目标?有没有人有一个例子,他们可以指出我实现类似的东西?

Tem*_*fif 6

您可以使用 mix-blend-mode:difference

body,
html {
  padding: 0;
  margin: 0;
}

.header {
  position: fixed;
  width: 100%;
  height: 50px;
  margin: 20px;
  color:#fff;
  mix-blend-mode: difference;
}

.section1,
.section2,
.section3{
  background: black;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.section2 {
  background: white;
  color:#000;
}
Run Code Online (Sandbox Code Playgroud)
<div class="header">
  Header Content
</div>
<div class="wrapper">
  <div class="section1">
    Section One Content
  </div>
  <div class="section2">
    Section Two Content
  </div>
  <div class="section3">
    Section Three Content
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)