使用背景图像并在其顶部应用CSS动画

时间:2013-11-09 19:24:46

标签: css css3 css-transitions

我创造了一个小提琴,但我不认为它显示正确。 http://jsfiddle.net/kVNQb/但无论如何都要查看代码可能会有用。

我正在使用CSS动画从此网站http://cssdeck.com/labs/css3-snow

创建雪

我想要做的是设置一个背景图像,然后在其上方设置雪的动画。目前我失去了动画雪或背景图像。

我是否需要创建一个ID并将我想要的图像设置为背景?

HTML代码

<body>

    <div class="row">
        <div class="large-12 columns">
            <div id="container">
        </div>
            </div>

    </div>

</body>

CSS代码

/*Custom CSS styles being used on top of the standard Foundation 4 style sheet*/
 fixed.body {
 background-image: url(http://s17.postimg.org/9htu61zjj/background.jpg);
}


* {
    margin: 0;
    padding: 0;
}

a {
    color: white;
    font-style: italic;
}

/*Keyframes*/

@keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

@-moz-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

@-webkit-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    50% { background-color: #b4cfe0 }

    100% {
        background-position: 500px 1000px, 400px 400px, 300px 300px;
        background-color: #6b92b9;
    }
}

@-ms-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

/*body {
    background-color: #6b92b9;
    background-image: url('http://img138.imageshack.us/img138/5230/snowh.png'), url('http://img594.imageshack.us/img594/9146/snow3q.png'), url('http://img196.imageshack.us/img196/5065/snow2l.png');
    -webkit-animation: snow 20s linear infinite;
    -moz-animation: snow 20s linear infinite;
    -ms-animation: snow 20s linear infinite;
    animation: snow 20s linear infinite;
}*/

#container {
    width: 800px;
    margin: 200px auto;
    text-align: center;
    color: white;
    font: 100px/1 'Spirax', cursive;
    text-shadow: 0px 0px 4px rgba(0,0,0, 0.5);
}

#container p { font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif }

2 个答案:

答案 0 :(得分:1)

在这种情况下,技巧是在div和动画帧中将background-color设置为透明。小提琴:http://jsfiddle.net/f92gB/

HTML:

<body>
    <div id="container"></div>
</body>

CSS:

* {
    margin: 0;
    padding: 0;
}

a {
    color: white;
    font-style: italic;
}

/*Keyframes*/

@keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

@-moz-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

@-webkit-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    50% { background-color: transparent }

    100% {
        background-position: 500px 1000px, 400px 400px, 300px 300px;
        background-color: transparent;
    }
}

@-ms-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

body {
    background-image: url("http://s17.postimg.org/9htu61zjj/background.jpg");
    background-size: cover;
    height: 500px;

}

#container {
    height:500px;
    margin: 0;
    text-align: center;
    color: white;
    font: 100px/1 'Spirax', cursive;
    text-shadow: 0px 0px 4px rgba(0,0,0, 0.5);
    background-color: transparent;
    background-image: url('http://img138.imageshack.us/img138/5230/snowh.png'), url('http://img594.imageshack.us/img594/9146/snow3q.png'), url('http://img196.imageshack.us/img196/5065/snow2l.png');
    -webkit-animation: snow 20s linear infinite;
    -moz-animation: snow 20s linear infinite;
    -ms-animation: snow 20s linear infinite;
    animation: snow 20s linear infinite;
}

答案 1 :(得分:0)

您可以使用此jQuery插件在您的网页上设置完整且响应迅速的背景图片,只需按照此链接中的说明操作即可。

http://johnpatrickgiven.com/jquery/background-resize/