肥宅综合社区-做一个优雅文明的综合社区

搜索内容

飞机窗帘开关动画,HTML+CSS实现

2023-10-05 227阅读 0评论

兄弟们下午好,今天给大家分享个HTML练手小代码,飞机窗帘开关

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Document</title>
  8.     <!--      引入css -->
  9.     <link rel="stylesheet" href="./style.css">
  10. </head>
  11. <body>
  12.     <!--在dom中增加表示云朵的.clouds元素.其中可以定义5个span子元素 分别代表1个云朵 -->
  13.     <input type="checkbox" class="toggle">
  14.     <figure class="window">
  15.         <!-- 窗帘 -->
  16.         <div class="curtain"></div>
  17.         <div class="clouds">
  18.             <span></span>
  19.             <span></span>
  20.             <span></span>
  21.             <span></span>
  22.             <span></span>
  23.         </div>
  24.     </figure>
  25. </body>
  26. </html>
CSS代码
  1. /* 初始化 */
  2. body{
  3.     margin: 0px;
  4.     height: 100vh;
  5.     /* 弹性布局 */
  6.     display: flex;
  7.     /* 水平居中 */
  8.     justify-content: center;
  9.     /* 上下居中 */
  10.     align-items: center;
  11.     /* 定义背景颜色 */
  12.     background-color: skyblue;
  13. }

  14. .window{
  15.     /* 相对定位 */
  16.     position: relative;
  17.     /* 盒子模型 */
  18.     box-sizing: border-box;
  19.     /* 窗户视图宽是125px不包含外边有box-shadow 画的外边框 */
  20.     width: 25em;
  21.     /* 窗户视图高是125px */
  22.     height: 35em;
  23.     font-size: 5px;
  24.     background-color: #d9d9d9;
  25.     /* 边框变圆 */
  26.     border-radius: 5em;
  27.     box-shadow:
  28.     /* 定义黑色边框 */
  29.     inset 0 0 8em rgba(0, 0, 0, 0.2),
  30.     /* 深灰色的边缘线 */
  31.     0 0 0 0.4em #808080,
  32.     0 0 0 4em whitesmoke,
  33.     /* 深灰色的边缘线 */
  34.     0 0 0 0.4em #808080,
  35.     /* 给阴影加一个原始尺寸 这个尺寸是由第四个参数决定的 */
  36.     0 2em 4em 4em rgba(0, 0, 0, 0.1);
  37.     /* 这个地方加个hidden 未来使下面用到定位的时候,top:-5%的时候 可以将溢出的部分隐藏 */
  38.     overflow: hidden;
  39. }

  40. /* curtain 是窗户的窗帘  和窗口尺寸一致 但不拉到底 */
  41. .window .curtain{
  42.     /* 绝对定位 */
  43.     position: absolute;
  44.     left: 0;
  45.     /* 相对于窗帘的高度 计算向上移动一点 */
  46.     top: -5%;
  47.     /* 继承父标签的尺寸 */
  48.     width: inherit;
  49.     height: inherit;
  50.     border-radius: 5em;
  51.     background-color: whitesmoke;
  52.     /* 给盖子加上边框 0.5em比上面的0,4em大一点能盖住之前的边框 */
  53.     box-shadow: 0 0 0 0.5em #808080,
  54.                 0 0 3em rgba(0, 0, 0, 0.4);
  55.                 /* 给top元素加上过渡效果 */
  56.     transition: top 0.5s ease-in-out;               
  57.     z-index: 2;
  58. }

  59. /* 当多选框被选中的时候, 窗帘网上飘走*/
  60. .toggle:checked ~ .window .curtain{
  61.     top: -90%;
  62. }


  63. /* 用伪类在窗帘上画出灰色长条 */
  64. .window .curtain::before{
  65.     content: '';
  66.     position: absolute;
  67.     width: 40%;
  68.     height: 0.8em;
  69.     background-color: #808080;
  70.     left: 30%;
  71.     bottom: 1.6em;
  72.     border-radius: 0.4em;
  73. }
  74. /* 用伪类在窗帘上画出径向渐变的指示灯 */
  75. .window .curtain::after{
  76.     content: '';
  77.     position: absolute;
  78.     width: 1.6em;
  79.     height: 0.8em;
  80.     background-image: radial-gradient(orange,orangered);
  81.     bottom: 1.6em;
  82.     /* 100% 值得是窗户视图的唯一指示灯宽度,然后咱们可以将剩余的距离居中 */
  83.     left: calc((100% - 1.6em)/2);
  84.     border-radius: 0.4em;
  85. }

  86. /* 当窗帘被选中的时候,颜色变成绿色 */
  87. .toggle:checked ~ .window .curtain::after{
  88.     background-image: radial-gradient(lightgreen,limegreen);
  89. }

  90. /* 隐藏checkbox  */
  91. .toggle{
  92.     /* 绝对定位 */
  93.     position: absolute;
  94.     width: 25em;
  95.     height: 35em;
  96.     font-size: 5px;
  97.     z-index: 3;
  98.     /* 鼠标放上变小手 */
  99.     cursor: pointer;
  100.     filter: opacity(0%);
  101. }

  102. /* 用云朵容器画出窗外的蓝天 */
  103. .window .clouds{
  104.     position: relative;
  105.     width: 20em;
  106.     height: 30em;
  107.     background-color: deepskyblue;
  108.     left: calc((100% - 20em)/2);
  109.     top: calc((100% - 30em)/2);
  110.     border-radius: 7em;
  111.     box-shadow: 0 0 0 0.4em #808080;
  112.     overflow: hidden;
  113. }

  114. /* 云朵画出来 */
  115. .clouds span{
  116.     position: absolute;
  117.     width: 10em;
  118.     height: 4em;
  119.     background-color: white;
  120.     border-radius: 4em;
  121.     top: 20%;
  122.     animation: move 4s linear infinite;
  123. }
  124. /* 定义动画 */
  125. @keyframes move{
  126.     from{
  127.         left: -150%;
  128.     }
  129.     to{
  130.         left: 150%;
  131.     }
  132. }
  133. /*   用伪元素 画 2个突起的圆弧 */
  134. .clouds span::before,
  135. .clouds span::after{
  136.     content: "";
  137.     position: absolute;
  138.     width: 4em;
  139.     height: 4em;
  140.     background-color: white;
  141.     border-radius: 50%;
  142. }

  143. .clouds span::before{
  144.     top: -2em;
  145.     left: 2em;
  146. }
  147. .clouds span::after{
  148.     top: -1em;
  149.     right: 1em;
  150. }

  151. .clouds span:nth-child(2){
  152.     top: 40%;
  153.     animation-delay: -1s;
  154. }

  155. .clouds span:nth-child(3){
  156.     top: 60%;
  157.     animation-delay: -0.5s;
  158. }
  159. .clouds span:nth-child(4){
  160.     top: 20%;
  161.     transform: scale(2);
  162.     animation-delay: -1.5s;
  163. }
  164. .clouds span:nth-child(5){
  165.     top: 70%;
  166.     /* 变大1.5呗 */
  167.     transform: scale(1.5);
  168.     animation-delay: -3s;
  169. }

文章版权声明:本站部分内容系网络转载,如果文章触发到您的利益或版权,请联系本站客服邮箱kefu@fz331.com删除,我们将48小时之内删除。

发表评论

上传附件:
评论列表 (有 0 条评论,227人围观)
切换注册

登录

忘记密码?

切换登录

注册

验证码