Hello i have actually a quiet simple question,
I have a counter running (a) and want to select an id with the counter: So if the counter (a) is "1", i expecte the ID #BG01 to be selected. But it don't do it. What am i declaring wrong ? i tried even +"a" to get a string but no.
Help please, thanks. ** Solved please see below the final code**
One question which came up during finalization: How can I pause the code for 1 sec, would like to pause the script while the top #BG fades in (not really a problem atm but you can see with a trained i the body BG for a split second, i assume thats because the script keeps on executing while css handles the transition so it would make sense to set it "onpause" for the time. i tried setTimeout but only with a length value it don't seems to work.. any ideas ? thanks
HTML:
<div id="container">
<div id="BG01"></div>
<div id="BG02"></div>
<div id="BG03"></div>
<div id="BG04"></div>
</div>
jQuery:
var b=0,
a=1;
setInterval ( function(){
if (b==0) { function() {
$('#BG0' + a).css({
"display": "block",
"z-index": "10",
"opacity": "1"});
b=2;
}
}
else {
if (b===5) { function() {
b=1;
$('#BG0' + a).css("z-index", "1");
$('#BG0' + b).css({
"z-index": "10",
"display": "block",
"opacity": "1"});
$('#BG0' + a).css({
"z-index": "-99",
"display": "none",
"opacity": "0"});
a=b;
b=++b;
}
}
else { function(){
$('#BG0' + a).css("z-index", "1");
$('#BG0' + b).css({
"z-index": "10",
"display": "block",
"opacity": "1"});
$('#BG0' + a).css({
"z-index": "-99",
"display": "none",
"opacity": "0"});
a=b;
b=++b;
}
}
}
}, 5000);
Final working Code:
var y=0;
var x=1;
function divcycle(){
$('#BG0'+ x).css("z-index", "1");
$('#BG0'+ y).css({
"z-index": "10",
"opacity": "1"});
$('#BG0'+ x).css({
"opacity": "0",
"z-index": "-99"});
x=y;
y=y+1;
}
setInterval ( function(){
if (y==0) {
$('#BG0' + x).css({
"z-index": "10",
"opacity": "1"});
y=2;
}
else {
if (y==5) {
y=1;
divcycle();
}
else {
divcycle();
}
}
}, 10000);