首页 > 解决方案 > jQuery水平多文本自动滚动一次

问题描述

我正在尝试创建一个水平的“新闻滚动条”,一次从右向左滚动一个文本。

我的代码不像我想的那样工作,它li一次显示了所有内容。有人可以在这里帮助我吗?也许必须用 jQuery 来完成?我尝试了我发现的不同方法,但没有一种方法能如我所愿。

谢谢

ul {
  width: 100%;
  height: 30px;
  overflow: hidden;
  position: relative;
  background: black;
  color: white;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  white-space: nowrap;
}

ul li {
  position: absolute;
  display: inline-block;
  width: 90%;
  height: 100%;
  font-size: 20px;
  line-height: 30px;
  margin: 0 auto;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  color: white;
  -moz-transform: translateX(100%);
  -webkit-transform: translateX(100%);
  transform: translateX(100%);
  -moz-animation: news_scroller 20s linear infinite;
  -webkit-animation: news_scroller 20s linear infinite;
  animation: news_scroller 20s linear infinite;
}
<ul class="news_scroller">
  <li>some text here askdadjsdkjaskjdkajs</li>
  <li>some more text here second news to show/scroll</li>
  <li>another one here bla bla bla</li>
  <li>sdfihjhgahr89we7 8rtgdsofui gysdhfhoj dsdf</li>
</ul>

标签: jquerycss

解决方案


这是你需要的吗?

/* (A) STANDARD ROW HEIGHT */
.vwrap, .vitem {
  height: 30px;
  line-height: 30px;
}
 
/* (B) FIXED WRAPPER */
.vwrap {
  overflow: hidden; /* HIDE SCROLL BAR */
  background: #eee;
}
/* (C) TICKER ITEMS */
.vitem { text-align: center; }
 
/* (D) ANIMATION - MOVE ITEMS FROM TOP TO BOTTOM */
/* CHANGE KEYFRAMES IF YOU ADD/REMOVE ITEMS */
.vmove { position: relative; }
@keyframes tickerv {
  0% { bottom: 0; } /* FIRST ITEM */
  30% { bottom: 30px; } /* SECOND ITEM */
  60% { bottom: 60px; } /* THIRD ITEM */
  90% { bottom: 90px; } /* FORTH ITEM */
  100% { bottom: 0; } /* BACK TO FIRST */
}
.vmove {
  animation-name: tickerv;
  animation-duration: 10s;
  animation-iteration-count: infinite;
  animation-timing-function: cubic-bezier(1, 0, .5, 0);
}
.vmove:hover { animation-play-state: paused; }
<div class="vwrap"><div class="vmove">
  <div class="vitem">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
  <div class="vitem">Aliquam consequat varius consequat.</div>
  <div class="vitem">Fusce dapibus turpis vel nisi malesuada sollicitudin.</div>
  <div class="vitem">Pellentesque auctor molestie orci ut blandit.</div>
</div></div>


推荐阅读