【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>
相关推荐
TT哇3 分钟前
【实习】数字营销系统 银行经理端(interact_bank)前端 Vue 移动端页面的 UI 重构与优化
java·前端·vue.js·ui
蓝帆傲亦4 分钟前
Web前端跨浏览器兼容性完全指南:构建无缝用户体验的最佳实践
前端
晴殇i8 分钟前
【前端缓存】localStorage 是同步还是异步的?为什么?
前端·面试
不一样的少年_10 分钟前
Chrome 插件实战:如何实现“杀不死”的可靠数据上报?
前端·javascript·监控
深度涌现10 分钟前
DNS详解——域名是如何解析的
前端
小码哥_常13 分钟前
Android内存泄漏:成因剖析与高效排查实战指南
前端
卤代烃13 分钟前
✨ 形势比人强,Chrome 大佬也去搞 Gemini 了
前端·agent·vibecoding
偶像佳沛14 分钟前
JS 对象
前端·javascript
Jing_Rainbow24 分钟前
【React-6/Lesson89(2025-12-27)】React Context 详解:跨层级组件通信的最佳实践📚
前端·react.js·前端框架
gustt24 分钟前
构建全栈AI应用:集成Ollama开源大模型
前端·后端·ollama