CSS3 视差滚动相册

tsx81428  金牌会员 | 2024-8-28 00:26:59 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 522|帖子 522|积分 1566

一个基于 CSS3 的视差滚动相册,采用网格布局(重要)与弹性布局。

     视差滚动相册
  
源代码如下:
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <title>旋转视差相册</title>
  7.   <style>
  8.     * {
  9.       margin: 0;
  10.       padding: 0;
  11.     }
  12.     .content {
  13.       width: 300px;
  14.       height: 300px;
  15.       margin: 0 auto;
  16.       margin-top: 100px;
  17.       display: grid;
  18.       /* 列 * 3,每列占 1/3,repeat的添加与否效果一致 */
  19.       /* grid-template-columns: repeat(3, 1fr);
  20.       grid-template-rows: (3, 1fr); */
  21.       /* grid-template 会覆盖前面的 grid-template-columns & grid-template-rows */
  22.       grid-template:
  23.         "A A B"
  24.         "C D B"
  25.         "C E E";
  26.       grid-gap: 10px;
  27.       padding: 10px;
  28.       border: 5px solid transparent;
  29.       border-image: linear-gradient(45deg, #df270ae0, #dc8d30, #deeb44, #01eb3e, #138fe9, #7127ee) 1;
  30.       animation: rotation 15s infinite linear;
  31.     }
  32.     .item {
  33.       overflow: hidden;
  34.       border: 1px solid #000;
  35.       display: flex;
  36.       align-items: center;
  37.       justify-content: center;
  38.     }
  39.     .item img {
  40.       animation: rotation1 15s infinite linear;
  41.       width: 300%;
  42.       height: 300%;
  43.       object-fit: cover;
  44.     }
  45.     .item:nth-child(1) {
  46.       grid-area: A;
  47.     }
  48.     .item:nth-child(2) {
  49.       grid-area: B;
  50.     }
  51.     .item:nth-child(3) {
  52.       grid-area: C;
  53.     }
  54.     .item:nth-child(4) {
  55.       grid-area: D;
  56.     }
  57.     .item:nth-child(5) {
  58.       grid-area: E;
  59.     }
  60.     @keyframes rotation {
  61.       to {
  62.         transform: rotate(360deg);
  63.       }
  64.     }
  65.     @keyframes rotation1 {
  66.       to {
  67.         transform: rotate(-360deg);
  68.       }
  69.     }
  70.   </style>
  71. </head>
  72. <body>
  73.   <div class="content">
  74.     <div class="item">
  75.       <img src="./static/pic1.jpg">
  76.     </div>
  77.     <div class="item">
  78.       <img src="./static/pic2.jpg">
  79.     </div>
  80.     <div class="item">
  81.       <img src="./static/pic3.jpg">
  82.     </div>
  83.     <div class="item">
  84.       <img src="./static/pic4.jpg">
  85.     </div>
  86.     <div class="item">
  87.       <img src="./static/pic5.jpg">
  88.     </div>
  89.   </div>
  90. </body>
  91. </html>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

tsx81428

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表