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



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

我正在使用CSS动画从这个网站创建雪 http://cssdeck.com/labs/css3-snow

我想做的是设置一个背景图像,然后让雪在上面动画化。目前,我丢失了动画雪或背景图像。

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

网页代码

<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 }

在这种情况下,诀窍是在div 和动画帧中将背景色设置为透明。小提琴: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;
}
您可以使用

此jQuery插件在您的页面上设置完整且响应式的背景图像,只需按照此链接中的说明进行操作即可。

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

相关内容

  • 没有找到相关文章

最新更新