前端(HTML+CSS+JS)简单项目第一天





  
  
  
  Expanding Cards



  

Explore The World

Wild Forest

Sunny Beach

City on Winter

Mountains - Clouds

CSS布局主要用的是flex弹性布局

@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');

* {
  box-sizing: border-box;
  /*使用H5标准的盒子模型*/
}

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: 0.5;
  margin: 10px;
  position: relative;
  -webkit-transition: all 700ms 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 0.3s ease-in 0.4s;
}

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

  .panel:nth-of-type(4),
  .panel:nth-of-type(5) {
    display: none;
  }
}

js就简单的多

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')
    })
}
//排他思想,当点击某一个图片时,先移除所有图片的class中的active样式,然后给点击的图片添加active样式

你可能感兴趣的:(html,前端,javascript)