CSS 实现无缝滚动

2023-12-14 18:48:50

效果展示

在这里插入图片描述

CSS 知识点

  • animation 综合运用

页面整体布局

<div class="scroll" style="--t: 20s">
  <div>
    <span>HTML</span>
    <span>CSS</span>
    <span>JavaScript</span>
    <span>React</span>
    <span>Vue</span>
    <span>Figma</span>
    <span>PhotoShop</span>
    <span>Angular</span>
  </div>
  <div>
    <span>HTML</span>
    <span>CSS</span>
    <span>JavaScript</span>
    <span>React</span>
    <span>Vue</span>
    <span>Figma</span>
    <span>PhotoShop</span>
    <span>Angular</span>
  </div>
</div>

核心样式

编写基础样式

.scroll {
  position: relative;
  display: flex;
  width: 700px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(
    90deg,
    transparent,
    #fff 20%,
    #fff 80%,
    transparent
  );
}

.scroll div {
  white-space: nowrap;
}

.scroll div span {
  display: inline-flex;
  margin: 10px;
  background: #333;
  color: #fff;
  padding: 5px 10px;
  border-radius: 5px;
  transition: 0.5s;
  letter-spacing: 0.2em;
}

.scroll div span:hover {
  background: #4caf50;
  cursor: pointer;
}

编写动画样式

.scroll div {
  white-space: nowrap;
}

@keyframes animate {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}

完整代码下载

完整代码下载

文章来源:https://blog.csdn.net/qq_33003143/article/details/134914068
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。