【发布时间】:2020-12-30 20:26:19
【问题描述】:
我一直在尝试弄清楚如何使用 No Gaps 获得类似字幕/自动收录器的效果。 我找到了一个使用这种技术的网站https://www.artpharmacy.com.au/(页面底部,“购买艾米莉亚的新书”)。
我试图复制他们所拥有的,因为这正是我想要的效果。
我相信他们实现这一点的方式是创建两个 span(每个 span 中的文本相同),然后使用 CSS 动画。如果有人可以解释这是如何工作的,那就太好了——我复制了代码,但我想了解它背后的逻辑。
- 我相信它首先会循环遍历第一个跨度的文本。然后我短暂地看到第二个跨度文本出现(我使用背景颜色:橙色来查看第二个跨度何时在动画中运行。)但是我看到在第二个跨度文本出现后,几秒钟,其他跨度标签的文本再次开始运行?两个 span 的动画是否同时发生?还是第一个跨度的动画先发生,然后是第二个跨度的动画?
我遇到的主要问题是:
-
我的 iphone (Safari) 上的动画很慢。我不知道为什么会这样?
-
有时动画看起来很生涩或“闪光”。我使用了线性和无限属性,不知道还有什么办法可以避免在浏览器之间造成这种不一致?
我还在滚动文本上使用混合混合模式,想知道它们是否也会导致奇怪的行为。 (注意:div 有一个背景图片,但我不知道如何在 sn-p 中添加它,所以只使用了 background-color:purple)
代码如下:
function makeMarquee() {
const title = 'Event: January 1-2, 2021, Zoom'
//use Array constructor to create an empty list with a length of 50 that is filled with the title.
//We can join all the contents of array using dash
const marqueeText = new Array(10).fill(title).join(' -- ')
//query Selector same as $ jquery, grab the span tags
const marquee = document.querySelector('.marquee span')
//set the text of span to be the marqueeText
marquee.innerHTML = marqueeText
// setTimeout(function () {marquee.style.animationName = 'moveLeft';},1000);
//create a clone of the div
var clone = marquee.cloneNode(true)
//add a class to this new div
clone.classList.add('marquee2')
//insert this new div after the first one
marquee.after(clone)
}
makeMarquee()
.section {
/*each section will take 100% of the height of browser */
min-height: 100vh;
/* Will help to vertically align container box */
display: flex;
position: relative;
}
/* Provide padding to left and right of section */
.section-pad {
padding-left: 5vw;
padding-right: 5vw;
}
.container {
/* Take the width of widest content box */
max-width: 780px;
/* Center our box horizontally and vertically using flex on .section */
margin: auto;
}
.intro {
background-image: url("intro-bg-min.png");
color: #fff;
background-color: purple;
}
.intro p {
font-size: 36px;
line-height: 1.2;
}
/* Utility class to center and cover background images */
.bg-cover {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.mix-difference {
/* our mix blend mode allows us to mix the current layer's style/colors with that of what's behind it to create some really cool effects */
mix-blend-mode: difference;
}
.marquee {
position: absolute;
top: 3vh;
left: 0;
width: 100%;
/*Each letter will be 5% of viewport width */
font-size: 5vw;
/* As tall as text */
line-height: 1;
text-transform: uppercase;
/*no scrollbars */
overflow: hidden;
white-space: nowrap;
/* Our span is inline by default, so change it to block */
}
.marquee span {
display: inline-block;
-webkit-animation: marquee 90s infinite linear;
animation: marquee 90s infinite linear;
}
@-webkit-keyframes marquee {
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
}
}
@keyframes marquee {
0% {
/* -webkit-transform: translateX(0);
transform: translateX(0); */
transform: translate(0, 0);
}
100% {
/* -webkit-transform: translateX(-100%);
transform: translateX(-100%); */
transform: translate(-100%, 0);
}
}
/* give the span a margin left equal to one width of letter */
.marquee2 {
margin-left: 5vw;
animation-delay: 45s;
background-color: orange;
}
/* Before the span give it a dash to make it flow with the existing content */
.marquee2::before {
content: " -- ";
}
<section class="intro section section-pad bg-cover" id="intro">
<div class="copy container">
<div class="marquee mix-difference">
<!-- Here we add the title in multiple repeating times using javascript -->
<span>Event: January 1-2, 2020, Zoom</span>
</div>
<div class="mix-difference ">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tristique tellus finibus velit bibendum pulvinar. Pellentesque id congue tellus. Donec a urna at tortor sagittis vulputate sed id turpis. Donec a urna at tortor sagittis vulputate sed id turpis.
</p>
</div>
</div>
<a href="#day-1" class="js-scroll scroll-to scroll-to-intro"></a>
</section>
【问题讨论】:
标签: javascript html css