如何使用CSS从右到左创建移动背景而不使用选框?

时间:2013-07-20 21:01:26

标签: html css

我想在标题中创建一个背景,它应该持续从右向左移动,图片应该重复。我不想在这里使用javascript。

1 个答案:

答案 0 :(得分:3)

用于此用途css3动画

它们使用非常简单

.hi {
    width: 50px;
    height: 72px;
    background-image: url("http://files.simurai.com/misc/sprite.png");

    -webkit-animation: play .8s steps(10) infinite;
       -moz-animation: play .8s steps(10) infinite;
        -ms-animation: play .8s steps(10) infinite;
         -o-animation: play .8s steps(10) infinite;
            animation: play .8s steps(10) infinite;
}

@-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; }
}


<img src="http://files.simurai.com/misc/sprite.png" />
<div class="hi"></div>

http://jsfiddle.net/simurai/CGmCe/light/