Raise the Curtains
스크롤의 배경이 dark 에서 light 으로 바뀌고, 위에 있는 내용도 sticky position 일 때, light 에서 dark으로 바뀌는 효과를 말한다.
오직, HTML 과 CSS로만 구현을 해볼 것이다.
<div class="curtain">
<div class="invert">
<h2>Curtain Effect</h2>
</div>
</div>
css 변수를 만들어 , 나중에 필요에 따라 쉽게 변경할 수 있도록 세팅한다.
:root {
--minh: 98vh;
--color1: wheat;
--color2: midnightblue;
}
가상 요소 (pseudo-element)를 사용하여 하단에 추가 공간을 만든다.
.curtain {
/** create the "split" background **/
background-image: linear-gradient(to bottom,
var(--color2) 50%, var(--color1) 50%);
}
/** add extra space to the bottom
(need this for the "sticky" effect) **/
.curtain::after {
content: "";
display: block;
min-height: var(--minh);
}
.invert {
/** make the content sticky **/
position: sticky;
top: 20px;
/** blend the content with the contrast effect **/
mix-blend-mode: difference;
/** center the content **/
display: flex;
align-items: center;
justify-content: center;
/** set the minimum height of the section **/
min-height: var(--minh);
}
h2 {
/** set the color of the text **/
color: var(--color1);
}
mix-blend-mode: difference ?
CSS를 이용하여 간단하게 텍스트 색상을 반전하는 방법이다.
값을 "difference"로 설정하면 아래 깔린 요소에 반전된 색상을 나타낼 수 있다.참고 사이트
- https://studiomeal.com/archives/888 (CSS 텍스트 반전 효과)
- https://studiomeal.com/archives/852 (CSS로 흑백이미지 만들기)