비전공자 개발일기

Javascript - Expanding Cards 본문

Javascript

Javascript - Expanding Cards

HiroDaegu 2021. 9. 25. 02:28
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>Expanding Cards</title>
  <link rel="stylesheet" href="style.css">
  <script defer src="main.js"></script>
</head>
<body>
  <div class="container">
    <div class="panel active" style="background-image: url('./images/1.jpg');">
      <h3>Explore the Space</h3>
    </div>
    <div class="panel" style="background-image: url('./images/2.jpg');">
      <h3>Explore the Space</h3>
    </div>
    <div class="panel" style="background-image: url('./images/3.jpg');">
      <h3>Explore the Space</h3>
    </div>
    <div class="panel" style="background-image: url('./images/4.jpg');">
      <h3>Explore the Space</h3>
    </div>
    <div class="panel" style="background-image: url('./images/5.jpg');">
      <h3>Explore the Space</h3>
    </div>
  </div>
</body>
</html>
@import url('https://fonts.googleapis.com/css2?family=Muli&display=swap');

* {
  box-sizing: border-box;
}

body {
  font-family: 'Muli', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  overflow: hidden;
  margin: 0;
}

.container {
  display: flex;
  width: 90vw;
}

.panel {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  height: 80vh;
  border-radius: 50px;
  color: #fff;
  cursor: pointer;
  flex: .5;
  margin: 10px;
  position: relative;
  transition: flex .7s ease-in;
}

.panel h3 {
  font-size: 24px;
  position: absolute;
  bottom: 20px;
  left: 20px;
  margin: 0;
  opacity: 0;
}

.panel.active {
  flex: 5;
}

.panel.active h3 {
  opacity: 1;
  transition: opacity .8s ease-in .4s;
}

@media(max-width: 480px) {
  .container {
    width: 100vw;
  }

  .panel:nth-of-type(4), 
  .panel:nth-of-type(5) {
    display: none;
  }
}
const panels = document.querySelectorAll(".panel");

panels.forEach(panel => {
  panel.addEventListener("click", () => {
    removeActiveClasses()
    panel.classList.add("active")
  })
})

function removeActiveClasses() {
  panels.forEach(panel => {
    panel.classList.remove("active")
  })
}
728x90
LIST

'Javascript' 카테고리의 다른 글

Javascript - Rotating Navigation  (0) 2021.09.27
Javascript - Progress Steps  (0) 2021.09.26
Javascript - Vertical Slider  (0) 2021.09.24
Javascript - Blurry Loading  (0) 2021.09.23
Javascript - Dynamic Banner  (0) 2021.09.22