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

标签 jquery css

// 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/

相关文章:

javascript - Phonegap 构建、HTML5 音频、Android

jquery - 多级 Bootstrap 菜单(在 Toranj 主题中)

javascript - 显示无属性会停止 Firefox 中的 youtube iframe 播放

javascript - 按按钮降序和升序排序

javascript - js onmouseover改变css

javascript - 如何在悬停在菜单上时替换图像

javascript - myswiper.slideTo() 不是函数

css - 文本输入响应宽度 - Bootstrap 3

css - 即使来源正确,@font-face 也不起作用

wordpress - 在网站上旋转我的 Logo