【HTML】实现商标滚动效果

CodePen

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
    <style>
      html,
      body {
        background: #f3f6fe;
      }
      .parent {
        width: 100%;
        height: 70px;
        white-space: nowrap;
        overflow: hidden;
      }
      .container-wrapper {
        position: relative;
      }
      .container {
        display: inline-block;
        white-space: nowrap;
        animation: scrollAnimation 20s linear infinite;
      }
      @keyframes scrollAnimation {
        0% {
          transform: translateX(0);
        }
        100% {
          transform: translateX(-100%);
        }
      }
      .child {
        display: inline-block;
        width: 168px;
        height: 70px;
        background: #fff;
        border-radius: 4px;
        box-shadow: 2px 8px 8px 2px #eaeef5;
        margin-right: 20px;
        overflow: hidden;
      }
      .child > img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
    </style>
  </head>
  <body>
    <div class="parent">
      <div class="container-wrapper">
        <div class="container" id="container">
          <div class="child">
            <img src="https://img1.baidu.com/it/u=4192660698,4228364625&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=375" />
          </div>
          <div class="child">
            <img src="https://img0.baidu.com/it/u=2073014214,797944792&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" />
          </div>
          <div class="child">
            <img src="https://img1.baidu.com/it/u=1112274159,2885021372&fm=253&fmt=auto&app=138&f=JPG?w=500&h=500" />
          </div>
          <div class="child">
            <img src="https://pic3.zhimg.com/v2-87d99f0c412221d15420a69e2150f78e_b.jpg" />
          </div>
          <div class="child">
            <img src="https://img2.baidu.com/it/u=4206423873,2794900790&fm=253&fmt=auto&app=138&f=JPEG?w=707&h=500" />
          </div>
          <div class="child">
            <img src="https://img0.baidu.com/it/u=3443668923,2767778850&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=375" />
          </div>
          <div class="child">
            <img src="https://img0.baidu.com/it/u=1435678765,4223566504&fm=253&fmt=auto&app=138&f=JPEG?w=527&h=395" />
          </div>
          <div class="child">
            <img src="https://img2.baidu.com/it/u=2883718771,2133249831&fm=253&fmt=auto&app=138&f=JPEG?w=660&h=500" />
          </div>
        </div>
        <div class="container" id="clone-container"></div>
      </div>
    </div>

    <script>
      document.addEventListener("DOMContentLoaded", function () {
        var container = document.getElementById("container");
        var cloneContainer = document.getElementById("clone-container");

        container.innerHTML += container.innerHTML; // 复制一份内容放到尾部

        container.addEventListener("animationiteration", function () {
          // 在每次动画迭代开始时,将 transform 设置回初始状态
          container.style.transform = "translateX(0)";
        });

        container.addEventListener("animationend", function () {
          // 在动画结束时,重置滚动位置
          container.style.transform = "translateX(0)";
        });

        // 每隔一段时间更新 clone-container 的内容,保持内容的连续性
        setInterval(function () {
          cloneContainer.innerHTML = container.innerHTML;
        }, 5000);
      });
    </script>
  </body>
</html>
相关推荐
0思必得013 分钟前
[Web自动化] 开发者工具性能(Performance)面板
运维·前端·自动化·web自动化·开发者工具
心灵的制造商17 分钟前
el-tree左侧新增类别和删除类别实例代码
前端·javascript·vue.js
爱吃无爪鱼19 分钟前
01-前端开发快速入门路线图
javascript·css·vue.js·typescript·前端框架·npm·node.js
冴羽20 分钟前
不知道怎么写 Nano Banana Pro 提示词?分享你一个结构化示例,复刻任意图片
前端·人工智能·aigc
IT_陈寒20 分钟前
JavaScript 性能优化:7个 V8 引擎隐藏技巧让你的代码提速200%
前端·人工智能·后端
脾气有点小暴27 分钟前
uniapp通用单张图片上传组件
前端·javascript·vue.js·uni-app·uniapp
小菜今天没吃饱32 分钟前
DVWA-XSS(stored)
前端·网络安全·xss·dvwa
云飞云共享云桌面33 分钟前
研发部门使用SolidWorks,三维设计云桌面应该怎么选?
运维·服务器·前端·网络·自动化·电脑
老华带你飞41 分钟前
茶叶商城|基于SprinBoot+vue的茶叶商城系统(源码+数据库+文档)
java·前端·javascript·数据库·vue.js·spring boot
烛阴43 分钟前
不只是Public与Private:C#访问修饰符全方位解读
前端·c#