Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!