gpt4 book ai didi

jquery - 尽管 100% translate tx 设置为 -100%,但 CSS 关键帧并未完全移出屏幕

转载 作者:行者123 更新时间:2023-11-28 00:41:55 25 4
gpt4 key购买 nike

// Sample items to add to the news-ticker
let sampleNewsItems = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"Vivamus enim magna, elementum in consectetur sit amet, porta ut eros"
];

// Iterate through the sample news items and process accordingly
let nextTimeoutDur;
for (let x = 0; x < sampleNewsItems.length; x++) {
let screenWidth = $(window).innerWidth();
$('.ticker-wrap').width(screenWidth);

$(".ticker-wrap").append('<div class="ticker-item" data-index="' + x + '"><span class="tickerContent"></span></div>');
$('.ticker-item[data-index="' + x + '"] .tickerContent').html(sampleNewsItems[x]);

let newsItemLength = 500;
$('.ticker-item[data-index="' + (x - 1) + '"]').outerWidth(500);

let tickerDur = 7;
nextTimeoutDur = x > 0 ? (tickerDur * newsItemLength) / screenWidth : 0;

$(".ticker-item[data-index=" + x + "]").css("animation", "ticker " + tickerDur + "s linear " + nextTimeoutDur + "s infinite");
}
@keyframes ticker {
0% {
transform: translate3d(100vw, 0, 0);
visibility: visible;
}
100% {
transform: translate3d(-100%, 0, 0);
}
}

.ticker-wrap {
width: 100%;
}

.ticker-wrap .ticker-item {
display: inline-block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="ticker-wrap"></div>

我想让第二个自动收报机元素在它消失之前完全离开视口(viewport),这就是为什么我设置 transform: translate3d(-100%, 0, 0); 100%关键帧。但是,一旦第一个消失,第二个股票元素就会从视口(viewport)中消失。为什么会这样?我该如何解决?

Here is a CodePen with my code.

https://codepen.io/prizzi13/pen/JwGmGE

最佳答案

.ticker-item

position 应该是 absolute

关于jquery - 尽管 100% translate tx 设置为 -100%,但 CSS 关键帧并未完全移出屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53776257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com