【问题标题】:CSS3 Marquee Effect, Without Empty SpaceCSS3 选框效果,没有空白
【发布时间】:2016-04-05 18:13:11
【问题描述】:

这个问题这里有一个答案,在选框的每次迭代结束时都会留下很多空白:CSS3 Marquee Effect

有没有办法实现平滑的<marquee></marquee> 效果,使用CSS3,不留这个空间?

我有很多小元素,看起来有点像 SO 的蓝色标签,专门填充选取框的内容,而不是一个连续的正文或一堵文字墙。

【问题讨论】:

  • 我的回答是否足够好,也可以被接受?
  • @LGSon,是的,谢谢您的回答。我不记得为什么我以前不接受它,但我可能是等到我尝试过然后忘记了。

标签: html css marquee


【解决方案1】:

这是一个示例,您可以通过设置延迟和持续时间来控制文本之间的间距

.marquee {
  background-color: #ddd;
  width: 500px;
  margin: 0 auto;
  overflow: hidden;
  white-space: nowrap;
}
.marquee span {
  display: inline-block;
  font-size: 20px;
  position: relative;
  left: 100%;
  animation: marquee 8s linear infinite;
}
.marquee:hover span {
  animation-play-state: paused;
}

.marquee span:nth-child(1) {
  animation-delay: 0s;
}
.marquee span:nth-child(2) {
  animation-delay: 0.8s;
}
.marquee span:nth-child(3) {
  animation-delay: 1.6s;
}
.marquee span:nth-child(4) {
  animation-delay: 2.4s;
}
.marquee span:nth-child(5) {
  animation-delay: 3.2s;
}

@keyframes marquee {
  0%   { left: 100%; }
  100% { left: -100%; }
}
<p class="marquee">
  <span>this is a</span>
  <span>simple marquee</span>
  <span>using css</span>
  <span>only tech</span>
  <span>with a delay</span>
</p>

【讨论】:

  • 如何开始“这是...”onload?
  • @saleemahmed 不确定我是否理解。此动画在页面加载时开始。如果要开始使用加载事件,只需将animation: marquee 8s linear infinite; 移动到它自己的类中,然后在事件处理程序中,将该类添加到marquee 元素中。
  • 谢谢兄弟,最好的主意
【解决方案2】:

CSS3 选框效果,没有空白

Horizontal Marquee

水平,一个和一个https://codepen.io/Rayeesac/pen/JjGEYRZ

Vertical Marquee

垂直,一个顶部和一个底部https://codepen.io/Rayeesac/pen/eYJgpVy

【讨论】:

    【解决方案3】:

    如果选框足够大,您可以在动画中间交换其中一个集合。

    我认为这是仅使用 CSS 所能达到的程度

    .marquee {
      width: 100%;
      height: 80px;
      margin: 0 auto;
      overflow: hidden;
      white-space: nowrap;
      border: 1px solid blue;
    }
    .marquee-content {
      display: inline-block;
      margin-top: 5px;
      animation: marquee 15s linear infinite;
    }
    .item-collection-1 {
      position: relative;
      left: 0%;
      animation: swap 15s linear infinite;
    }
    @keyframes swap {
      0%, 50% {
        left: 0%;
      }
      50.01%,
      100% {
        left: 100%;
      }
    }
    .marquee-content:hover {
      animation-play-state: paused
    }
    .item1 {
      display: inline-block;
      height: 70px;
      width: 140px;
      background: cyan;
      vertical-align: top;
      margin-left: 15px;
    }
    .item2 {
      display: inline-block;
      height: 70px;
      width: 100px;
      background: magenta;
      vertical-align: top;
      margin-left: 15px;
      line-height: 14px;
    }
    /* Transition */
    
    @keyframes marquee {
      0% {
        transform: translateX(0)
      }
      100% {
        transform: translateX(-100%)
      }
    }
    <div class="marquee">
    <div class="marquee-content">
        <span class="item-collection-1">
            <span><img src="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png" height="80"></span>
            <span class="item1"></span>
            <span><img src="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png" height="80"></span>
            <span class="item1"></span>
            <span class="item1"></span>
            <span class="item1"></span>
            <span class="item1"></span>
        </span>
        <span class="item-collection-2">
            <span class="item2"></span>
            <span class="item2"></span>
            <span class="item2"></span>
            <span class="item2"></span>
            <span class="item2"></span>
            <span class="item2"></span>
            <span class="item2"></span>
            <span class="item2"></span>
        </span>
    </div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-29
      相关资源
      最近更新 更多