비전공자 개발일기

Corner Text Parallax Effects 본문

HTML _CSS

Corner Text Parallax Effects

HiroDaegu 2022. 9. 17. 00:17
728x90
SMALL

 

<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Corner Text Parallax Effects</title>
    <link rel="stylesheet" href="style.css" />
    <script defer src="main.js"></script>
  </head>
  <body>
    <section>
      <div class="skew1">
        <h2 class="layer">Corner Text</h2>
      </div>
      <div class="textBox">
        <div class="skew2">
          <h2 class="layer">Corner Text</h2>
        </div>
      </div>
    </section>
  </body>
</html>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  position: relative;
}

section {
  width: 100%;
  height: 100vh;
  background-color: #222;
  overflow: hidden;
}

section .textBox {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #333;
  clip-path: polygon(0 0, 50% 0, 50% 100%, 0% 100%);
}

.skew1 h2, .textBox .skew2 h2 {
  position: absolute;
  width: 100%;
  text-align: center;
  font-size: 12em;
  line-height: 1em;
  color: #0488F5;
  cursor: pointer;
}

.skew1 h2 {
  opacity: .6;
}

.skew1 {
  top: 50px;
  transform: skewY(20deg);
}

.skew2 {
  top: 50px;
  transform: skewY(340deg);
}
document.addEventListener("mousemove", parallaxText);

function parallaxText(e) {
  this.querySelectorAll(".layer").forEach((layer) => {
    let x = (window.innerWidth - e.pageX * 2) / 2;
    layer.style.transform = `translateX(${x}px)`;
  });
}
728x90
LIST

'HTML _CSS' 카테고리의 다른 글

Text Animation & BG  (0) 2022.09.25
Slide Sign In & Up  (0) 2022.09.20
Gradient Circle Text  (0) 2022.09.15
Christmas Tree  (0) 2022.09.13
Growing Smiley Face Effects  (0) 2022.09.12