最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论
<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.)

<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.)

Share Improve this question edited Dec 3, 2010 at 3:25 TIMEX asked Dec 3, 2010 at 3:19 TIMEXTIMEX 273k368 gold badges802 silver badges1.1k bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5
@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)

  1. 暂无评论