0

I tried to change my background image with the following code

$('#mask').css({'background-image' : 'url('changingVar')', 
    'background-repeat' : 'no-repeat',  
    'background-position': 'center',
    'background-size': 'cover',         
}); 

and having a setTimeout for the waiting time.

However I want a changing animation kinda like : http://www.luckywok.at

The problem is when I use fadeout and fadeIn it's fading out and in my complete screen, since I have a wrapper DIV (#Mask) around everything.

Does anyone have an idea what methods were used on that particular site?

4
  • Have you tried toggleClass()? Commented Jan 13, 2014 at 19:57
  • 1
    typically you would stack a bunch of images on top of each other using z-index / absolute positioning, and then fade those in and out. Commented Jan 13, 2014 at 20:02
  • There are some jquery plugin that you can use to do these kind of background effects : jquery4u.com/plugins/… Commented Jan 13, 2014 at 20:03
  • change 'url('changingVar')' to 'url(' + changingVar + ')'. Also, you should probably pick a better variable name than changingVar. Commented Jan 13, 2014 at 20:03

2 Answers 2

2

Simple solution.

Fullscreen : http://jsfiddle.net/9GwNG/3/show/

jsfiddle : http://jsfiddle.net/9GwNG/3/

// code was written in a hurry
//
var step = 1;

function bg(){
 var opacity = 0.0;
 if (step == 3){
  n = 3;
  step = 1;
  opacity = 1.0;
  $("#item_"+step).animate({'opacity':opacity},2000);     
  $("#item_"+n).animate({'opacity': 0.0},2000);
  return;     
}
  n = step+1;
  $("#item_"+step).animate({'opacity':opacity},2000);
  $("#item_"+n).animate({'opacity':1.0},2000);
  step = n;
}

function loop(){
 setInterval(bg,4000);    
}

setTimeout(loop,500);
Sign up to request clarification or add additional context in comments.

Comments

0

Just use CSS- Transitions and a setInterval function. http://jsbin.com/ugERaZO/1/edit

Transitions are support for > ie9 see caniuse.

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.