CSS 实现无缝滚动

效果展示

CSS 实现无缝滚动_第1张图片

CSS 知识点

  • animation 综合运用

页面整体布局

<div class="scroll" style="--t: 20s">
  <div>
    <span>HTMLspan>
    <span>CSSspan>
    <span>JavaScriptspan>
    <span>Reactspan>
    <span>Vuespan>
    <span>Figmaspan>
    <span>PhotoShopspan>
    <span>Angularspan>
  div>
  <div>
    <span>HTMLspan>
    <span>CSSspan>
    <span>JavaScriptspan>
    <span>Reactspan>
    <span>Vuespan>
    <span>Figmaspan>
    <span>PhotoShopspan>
    <span>Angularspan>
  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%);
  }
}

完整代码下载

完整代码下载

你可能感兴趣的:(CSS,css,前端)