0

So here is my app.js

$(document).ready(function() {
var cnt=0, bg;
var $body = $('body');
var arr = ['http://www.writerscentre.com.au/wp-content/uploads/2013/12/Writing-Picture-Books-grid.jpg','bg2.jpg','bg3.jpg','bg4.jpg','bg5.jpg','bg6.jpg'];
var anim;
var bgrotater = setInterval(function() {
    if (cnt==5) cnt=0;
    bg = 'url("' + arr[cnt] + '")';
    cnt++;
    $body.css('background-image', bg);
   /* $body.animate({
        background-image = bg;
    },200)
    */

}, 1000);


 });

the $body.css works fine but can i get this to work with .animate()

6
  • 4
    And what do you expect animating the background image to do? Commented Sep 7, 2014 at 17:18
  • I wanted to make it fade in and out Commented Sep 7, 2014 at 17:20
  • @user, you would need to find (or write) a specific plugin to achieve that. Neither jQuery not jQuery UI support this feature out of the box. Commented Sep 7, 2014 at 17:21
  • Now im sad lol... Is their any other way to achieve this? Commented Sep 7, 2014 at 17:22
  • use $body.animate({opacity:0}, 'slow', function() {$(this).animate({opacity: 1})}) for fade effect Commented Sep 7, 2014 at 17:22

1 Answer 1

1

animate takes an object but you are defining the property like you define a variable.

Also due to the dash you need quotes around the property key.

background-image = bg;

Should be

"background-image": bg

The background image will not fade in and out though, it takes a lot more to do that, and animating opacity will fade in and out the element not the background.

There is a plugin that probably will help you do what you want see: Vegas Background

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.