css - CSS - 有没有更好的方法来创建从框的边缘出现和消失的滚动重复文本?
问题描述
.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
这是在滚动列表中一遍又一遍地重复“会议”之类的词的方框中的效果。查看他们的源代码,似乎他们在一系列相同的 div 中重复相同的单词,然后使用 transform: translate 在无限循环中对它们进行动画处理。那部分很简单,但是如果有意义的话,让顶行从框“外部”进入框更难,就像底部文本退出框一样。顶线突然出现。
我用一个覆盖框解决了这个问题,该框的轮廓带有负偏移,就像边缘周围的内部蒙版,然后是另一个提供边框的框。
但我想知道是否有更简单的方法来解决这个问题?
任何帮助或想法都会很棒,谢谢!
解决方案
你的问题是这两行:
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>
推荐阅读
- python-3.x - 向上和向下箭头在 tkinter.Entry 小部件中插入不需要的字符
- ag-grid - 如何按行在 Ag-grid 中添加特定组件(如输入组件),或者如何在 Ag-grid 中按行删除组件?
- r - 需要一个包含相交值计数的矩阵
- redis - 如何运行redis sentinel监控redis服务器
- python - 读取文本文件时为空 json 对象
- python-2.7 - 为什么我的代码只输出第一个和最后一个输入的答案?
- c++ - 无法将json数据写入c ++中的文件
- python - 如何从 Python 列表中返回嵌套的频率列表?
- android - 在片段中按下后退按钮时如何显示警告消息
- amazon-web-services - 如何使用 yaml 格式文件在 serverless.yml 中编写嵌套 IF,同时将其用于云形成?