首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS关键帧不会完全移出屏幕,尽管100%转换tx设置为-100%

CSS关键帧不会完全移出屏幕,尽管100%转换tx设置为-100%
EN

Stack Overflow用户
提问于 2018-12-14 16:51:22
回答 1查看 44关注 0票数 0

代码语言:javascript
复制
// 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");
}
代码语言:javascript
复制
@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;
}
代码语言:javascript
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="ticker-wrap"></div>

我想让第二个滚动条项目在它消失之前完全离开视口,这就是为什么我将transform: translate3d(-100%, 0, 0);设置为100%的关键帧。但是,第一个滚动条一消失,第二个滚动条就会从视口中消失。为何会这样呢?我怎么才能修复它呢?

Here is a CodePen with my code.

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

EN

回答 1

Stack Overflow用户

发布于 2019-01-13 04:49:24

.ticker-itemposition应为absolute

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53776257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档