如何停止字幕文本,然后继续

时间:2016-10-05 14:11:57

标签: javascript jquery html marquee

我希望文本滑入,然后当它居中时等待几个然后继续并重复该过程。有谁知道怎么做?

以下是我的代码:

<marquee direction="left" id="artistslide">
    <span id="currentartist"><i class="fa fa-spinner fa-spin"></i></span>
</marquee>

<marquee direction="right" id="currentsongslide">
    <span id="currentsong"><i class="fa fa-spinner fa-spin"></i></span>
</marquee>

然后我让JS做一个计时器,但它并不总是正确的,因为它不断计时:

var start = true;
setInterval(passStartMarquee, 3000 );
// adjust the delay

function passStartMarquee() 
{
    if (start) {
      document.getElementById('currentsongslide').start();
      document.getElementById('artistslide').start();
      start = false;
     } else {
       document.getElementById('currentsongslide').stop();
       document.getElementById('artistslide').stop();
       start = true;
     }     
}

1 个答案:

答案 0 :(得分:1)

以下是this tutorial

上的代码

.example1 {
  height: 50px;
  overflow: hidden;
  position: relative;
}
.example1 h3 {
  position: absolute;
  width: 100%;
  height: 100%;
  margin: 0;
  line-height: 50px;
  text-align: center;
  /* Starting position */
  -moz-transform: translateX(100%);
  -webkit-transform: translateX(100%);
  transform: translateX(100%);
  /* Apply animation to this element */
  -moz-animation: example1 10s linear infinite;
  -webkit-animation: example1 10s linear infinite;
  animation: example1 10s linear infinite;
}
/* Move it (define the animation) */

@-moz-keyframes example1 {
  0% {
    -moz-transform: translateX(100%);
  }
  40% {
    -moz-transform: translateX(0%);
  }
  60% {
    -moz-transform: translateX(0%);
  }
  100% {
    -moz-transform: translateX(-100%);
  }
}
@-webkit-keyframes example1 {
  0% {
    -webkit-transform: translateX(100%);
  }
  40% {
    -webkit-transform: translateX(0%);
  }
  60% {
    -webkit-transform: translateX(0%);
  }
  100% {
    -webkit-transform: translateX(-100%);
  }
}
@keyframes example1 {
  0% {
    -moz-transform: translateX(100%);
    /* Firefox bug fix */
    -webkit-transform: translateX(100%);
    /* Firefox bug fix */
    transform: translateX(100%);
  }
  40% {
    -moz-transform: translateX(0%);
    /* Firefox bug fix */
    -webkit-transform: translateX(0%);
    /* Firefox bug fix */
    transform: translateX(0%);
  }
  60% {
    -moz-transform: translateX(0%);
    /* Firefox bug fix */
    -webkit-transform: translateX(0%);
    /* Firefox bug fix */
    transform: translateX(0%);
  }
  100% {
    -moz-transform: translateX(-100%);
    /* Firefox bug fix */
    -webkit-transform: translateX(-100%);
    /* Firefox bug fix */
    transform: translateX(-100%);
  }
}
<div class="example1">
  <h3>I'll pause so you can read me.</h3>
</div>

<div class="example1">
  <h3>I'll pause so you can read me.</h3>
</div>