Dano007
Dano007

Reputation: 1932

Use background image and apply CSS animations over the top of it

I've created a fiddle, but I dont think its displaying correctly. http://jsfiddle.net/kVNQb/ but it might be useful to view the code anyway.

I'm using a CSS animation to create snow from this site http://cssdeck.com/labs/css3-snow

What I'd like to do is set a background image and then have the snow animate over the top of this. At the moment I lose either the animated snow or the background image.

Do i need to create a id and set the image I want as a background to that?

HTML code

<body>

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

    </div>

</body>

CSS code

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

Upvotes: 2

Views: 4572

Answers (2)

Kerry Liu
Kerry Liu

Reputation: 2162

In this case the trick is to set the background-color to transparent in both the div and in the animation frames. Fiddle: 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;
}

Upvotes: 1

Joe RR
Joe RR

Reputation: 262

you can use this jQuery plugin to set a full and responsive background image at your page, just follow the instructions at this link.

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

Upvotes: 0

Related Questions