简体   繁体   中英

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

<div class="abc">
</div>


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

My background 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 (eg @-moz-keyframes @-o-keyframes @-webkit-keyframes etc.).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM