Move multiple backgrounds infinitely using CSS

后端 未结 3 918
予麋鹿
予麋鹿 2021-01-07 08:45

I have two backgrounds:

body {
    background-image: url(img/nemo.png),url(img/ocean.png);
}

How do I make nemo.png background

3条回答
  •  生来不讨喜
    2021-01-07 09:28

    This can be done with pure CSS 3, e.g keyframed animations:

    Demo: http://jsfiddle.net/dghsV/112

    body {
        background-image: url("http://www.animaatjes.nl/disney-plaatjes/disney-plaatjes/finding-nemo/nemo11.gif"), url("http://images2.layoutsparks.com/1/200022/ocean-dreams-blue-waves.jpg");
        background-repeat: no-repeat;
        background-position: 50% 0%, 0;
        -moz-animation: swim 2s linear 0s infinite;
        -webkit-animation: swim 2s linear 0s infinite;
        animation: swim 2s linear 0s infinite;
    }
    @-moz-keyframes swim {
        from { background-position: 200% 0, 0 0; }
        to  { background-position: -100% 0, 0 0; }
    }
    @-webkit-keyframes swim {
        from { background-position: 200% 0, 0 0; }
        to  { background-position: -100% 0, 0 0; }
    }
    @keyframes swim {
        from { background-position: 200% 0, 0 0; }
        to  { background-position: -100% 0, 0 0; }
    }
    

    Syntax

    animation : animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction;

    The feature is experimental, so vendor-prefixes (eg -webkit-) have to be added (see also Can I use CSS3 Animation for compatibility notes). In my demo, I've used all properties, except for the last one.

提交回复
热议问题