尽管100%将tx设置为-100%,CSS关键帧仍无法完全移出屏幕

时间:2018-12-14 08:51:22

标签: jquery css3

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

我想让第二个自动收录机项目完全消失在视口之前,这就是为什么我为关键帧的100%设置transform: translate3d(-100%, 0, 0);的原因。但是,第二个股票行情项目在第一个项目消失后便会从视口中消失。为什么会这样呢?我该如何解决?

Here is a CodePen with my code.

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

1 个答案:

答案 0 :(得分:0)

static const volatile union中的

position应该是.ticker-item