Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Dean Yeong
Dean Yeong
10,053 Points

CSS to Change Background

I am facing some problem on css to change background in different browser. Here is something I had done.

@-webkit-keyframes change-background {
  0% {background: url('../asset/stressed_linen_@2X.png') repeat;}
  100% {background: url('../asset/shattered_@2X.png') repeat;}
}

@-moz-keyframes change-background {
  0% {background: url('../asset/stressed_linen_@2X.png') repeat;}
  100% {background: url('../asset/shattered_@2X.png') repeat;}
}

After setting up the keyframes, I wrote these.

.container {
  -webkit-animation-name: change-background;
     -moz-animation-name: change-background;
  -webkit-animation-delay: 4s;
     -moz-animation-delay: 4s;
  -webkit-animation-duration: 1.5s;
     -moz-animation-duration: 1.5s;
  -webkit-animation-iteration-count: 1;
     -moz-animation-iteration-count: 1;
  -webkit-animation-fill-mode: forwards;
     -moz-animation-fill-mode: forwards;
}

But as results, the keyframe is working well in Chrome and Safari, but not in Mozilla Firefox, is there any mistake on my Mozilla prefix?

2 Answers

Unfortunately, this only works in -web-kit (chrome, safari etc) at present. In firefox, background image isn't a property that can be animated / tweened.

You could do something like lay a series of div's (with your background images) on top of each other using position: absolute. You could then animate the opacity of these divs to 0 - leaving the one you want at 100% (a sort of flick book effect).

Firefox should implement this feature soon - Webkit does seem to be leading the way.

Dean Yeong
Dean Yeong
10,053 Points

Thanks for your information!