Here is my code:
elem.animate({ background-image: "url(" + imagedir + backgrounds[i] + ")" }, 1500 );
});
But apparently this is invalid, can anyone see why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re not telling us what program is giving what errors (is it the browser console? A validator?), but I’m pretty sure it won’t work (if that’s what you mean by invalid) due to the fact you can’t animate
background-image.DreamWeaver will be moaning at you probably because
background-imageisn’t a JavaScript CSS attribute. UsebackgroundImageor, specifically to jQuery, wrap it in quotes:"background-image". To simply change the background image, use.css()instead of.animate(), but this won’t fade it. Is the image a single colour or an actual image?If you want to fade between two images, there is a solution using two separate images, one inside a container. There’s a JSFiddle here demonstrating this.
HTML
CSS
jQuery