选框开始和停止

时间:2015-03-23 19:01:00

标签: javascript jquery html onclick marquee

我想要一个向左滚动的图片选框,当你点击它们时它们会停止,当你再次点击它们时它们会继续向左移动。我知道marquee代码,但你如何在Java或jQuery中编写该函数?

1 个答案:

答案 0 :(得分:0)

以下演示了切换css动画的播放状态以暂停和播放选框/幻灯片/动画。

动画使用background-position样式声明来更改背景图像的显示位置,如下所示:

Several Images in a sequence

// adapted from simurai's fiddle: http://jsfiddle.net/simurai/CGmCe/light/

var elm = document.querySelector("div.hi");
function pause() {
    console.log(elm);
    elm.className = "hi stop";
    elm.onclick = play;
}

function play()
{
    elm.className = "hi";
    elm.onclick = pause;    
}

elm.onclick = pause;
.hi {
    width: 50px;
    height: 72px;
    background-image: url("http://s.cdpn.io/79/sprite-steps.png");
    
    -webkit-animation: play 8s steps(1000) infinite;
       -moz-animation: play 8s steps(1000) infinite;
        -ms-animation: play 8s steps(1000) infinite;
         -o-animation: play 8s steps(1000) infinite;
            animation: play 8s steps(1000) infinite;
}

.hi.stop {
    -webkit-animation-play-state: paused;
    animation-play-state: paused;
}


@-webkit-keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

@-moz-keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

@-ms-keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

@-o-keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

@keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}
<div class="hi"></div>