CSS - 有没有更好的方法来创建滚动的重复文本,这些文本在框的边缘出现和消失?

标签 css layout css-animations

.container {
      font-family: sans-serif;
      font-size: 30px;
      position: relative;
    /*   border: 1px solid #000; */
      width: 90%;
      margin: 0 auto;
      overflow: hidden;
      text-align: center;
      margin-top: 10px;
    }
    
    .individual {
      animation: scroll 500ms linear infinite;
      }
    
    @keyframes scroll {
      100% {
        transform: translateY(100%);
      }
    }
    
    .overlay-1 {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: none;
      outline: 20px solid #fff;
      outline-offset: -20px;
    }
    
    .overlay-2 {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      opacity: 1;
      background-color: none;
      z-index: 2;
      outline: 2px solid #000;
      outline-offset: -20px;
    }
<div class="container">
 
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>

<div class="overlay-1"></div>
<div class="overlay-2"></div>
  
</div>

我正在尝试弄清楚如何重新创建此站点上使用的效果: https://inthecity.strelka.com/en

这是方框中的效果,在滚动列表中一遍又一遍地重复“ session ”这样的词。查看他们的源代码,似乎他们在一系列相同的 div 中重复同一个词,然后使用 transform: translate 在无限循环中为它们设置动画。那部分很简单,但是很难让顶行从框的“外部”进入框,就像底部文本退出框一样,如果这有意义的话。顶行突然出现。

我用一个覆盖框解决了这个问题,该框具有带负偏移的轮廓,就像围绕边缘的内部 mask ,然后是另一个框来提供边框。

但我想知道是否有更简单的方法来解决这个问题?

任何帮助或想法都会很棒,谢谢!

最佳答案

你的问题是这两行:

outline: 20px solid #fff;
outline-offset: -20px;

我已经使用正确的代码实现了下面的代码片段。

.container {
      font-family: sans-serif;
      font-size: 30px;
      position: relative;
    /*   border: 1px solid #000; */
      width: 90%;
      overflow: hidden;
      text-align: center;
      margin-top: 10px;
    }
    
    .individual {
      animation: scroll 1000ms linear infinite;
      }
    
    @keyframes scroll {
      100% {
        transform: translateY(100%);
      }
    }
    
    .overlay-1 {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: none;
      outline: 50px solid #fff;
      outline-offset: -30px;
    }
    
    .overlay-2 {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      opacity: 1;
      background-color: none;
      
      outline: 2px solid #000;
      outline-offset: -20px;
    }
<div class="container">
 
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>
<div class="individual">
  <div class"words">HELLO TO YOU</div>
</div>

<div class="overlay-1"></div>
<div class="overlay-2"></div>
  
</div>

关于CSS - 有没有更好的方法来创建滚动的重复文本,这些文本在框的边缘出现和消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53585698/

相关文章:

css - 如何使用 GWT 2.4 和 uiBinder 添加空格?

javascript - 如何自动滚动到列表中最后插入的值(非底部)。[[注 :List is Sorted]]

css - 使动画像过渡悬停一样悬停

html - 保留 CSS 动画中的最后一个关键帧属性

jquery - CSS 过渡不适用于 DOM 操作

javascript - 鼠标仅在您到达特定点时才会悬停,而不是在整个文本上悬停

html - 我怎样才能使移动文本逐渐消失并重新出现而不是在动画结束时传送?

javascript - 如何使用 jQuery 将此元素从悬停效果更改为点击效果?

CSS 100% 高度布局

html - 我应该在标记中使用 <p/> 标签吗?