开发者

How do I use CSS3 animate to move the background image of a div up and down?

开发者 https://www.devze.com 2023-01-28 07:47 出处:网络
<div class=\"abc\"> </div> .abc{ background: url(\"blah.jpg\") no-repeat; width:200px; height:200px;
<div class="abc">
</div>


.abc{
    background: url("blah.jpg") no-repeat;
    width:200px;
    height:200px;
}

My backgrou开发者_如何学编程nd image is 200 x 600. How do I move it up and down the div (I want the div to remain 200x200, but the longer image goes up and down.)

I don't want to use Javascript to do this. (Because doing it that way won't use the hardware and will be slow.)


@keyframes bounce-background {
    from {
        background-position: top;
    }
    50% {
        background-position: bottom;
    }
    to {
        background-position: top;
    }
}
.abc {
    animation-name: bounce-background;
    animation-timing-function: ease-in-out;
    animation-duration: 2s;
    animation-iteration-count: infinite;

    /* For Chrome & Safari */
   -webkit-animation-name: bounce-background;
   -webkit-animation-timing-function:ease-in-out;
   -webkit-animation-duration:2s;
   -webkit-animation-iteration-count:infinite;
}

You should repeat these non-finalized CSS3 properties under vendor prefixes for the browsers you're supporting (e.g. @-moz-keyframes @-o-keyframes @-webkit-keyframes etc.).

0

精彩评论

暂无评论...
验证码 换一张
取 消