• 前端50天50个项目 | 第1个项目 -- 扩展卡片【提供完整代码】


    前言❤️ 如果预计中的不幸没有发生的话,我们就会收获意外的喜悦 ❤️

    前端50天50个项目 | 第1个项目 -- 扩展卡片【提供完整代码】

    一、效果图展示

    在这里插入图片描述


    二、完整代码演示

    (1)index.html

    DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="stylesheet" href="style.css" />
        <title>第一个项目:扩展卡片title>
      head>
      <body>
        <div class="container">
          <div class="panel active" style="background-image: url('https://images.unsplash.com/photo-1558979158-65a1eaa08691?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
            <h3>Explore The Worldh3>
          div>
          <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1572276596237-5db2c3e16c5d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
            <h3>Wild Foresth3>
          div>
          <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1507525428034-b723cf961d3e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1353&q=80')">
            <h3>Sunny Beachh3>
          div>
          <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1551009175-8a68da93d5f9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1351&q=80')">
            <h3>City on Winterh3>
          div>
          <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
            <h3>Mountains - Cloudsh3>
          div>
        div>
        <script src="script.js">script>
      body>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    (2)style.css

    @import url('https://fonts.googleapis.com/css?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: 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;
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63

    (3)script.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')
      })
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    三、总结

    😝 我会坚持一直更新呢!喜欢的朋友们记得点点赞哦!有问题的小伙伴可以在下面评论区留言哦! 😝

  • 相关阅读:
    xss反射型漏洞复现
    自主研发的流程引擎怎么样?好用吗?
    Linux下自动挂载U盘或者USB移动硬盘
    Python 算法高级篇:快速排序的优化算法
    机房工程实习报告怎么写2500字
    第52节:cesium 3DTiles模型特效+选中高亮(含源码+视频)
    macos 上彻底卸载 DevEco Studio
    27、商户查询缓存(添加商户缓存)
    应用系统与外设对接步骤
    NR 物理层编码 - slide4 循环码Cyclic Code
  • 原文地址:https://blog.csdn.net/battledao/article/details/126020986