What variable is changing?
Please tell me what variable is changing on the loop so I can maybe create a if else statement. I'm not a developer so, I really need help. Here's the code
$(document).ready(function(){
$("#health").show();
$("#health").hide();
$("#billing").hide();
var arr = [
$("#pension"),
$("#health"),
$("#billing")
];
var cur = 0, nxt = 1;
function looptour(ncur){
if(ncur!=undefined) {
arr[cur].hide();
arr[ncur].show();
cur = ncur;
nxt = (cur + 1 < arr.length) ? cur + 1 : 0;
}
else {
setInterval(function() {
arr[cur].fadeOut(2000);
arr[nxt].fadeIn(2000);
cur = (cur + 1 < arr.length) ? cur + 1 : 0;
nxt = (nxt + 1 < arr.length) ? nxt + 1 : 0;
},6000);开发者_如何学C
}
}
looptour();
This is what I wanted to do... I just don't know the variable to use. Here's the idea, I have 3 buttons "1 2 3" I just want to add a class to those individual buttons 1 is for pension 2 is for health 3 is for billing
Thank you!
if() {
$("#tournums ul li:first a").addClass("num_active");
} else if() { $("#tournums ul li:eq(1) a").addClass("num_active");
} else if() { $("#tournums ul li:eq(2) a").addClass("num_active");
}
EDIT: A little better than my original answer, since it caches the elements.
If I understand what you need correctly, I'd do this:
Try it out: http://jsfiddle.net/aTTrr/1
var arr = [
$("#pension"),
$("#health").hide(),
$("#billing").hide()
];
var $aElements = $("#tournums ul li a");
var cur = 0, nxt = 1;
setInterval(function() {
arr[cur].fadeOut(2000);
arr[nxt].fadeIn(2000);
$aElements.removeClass('num_active');
$aElements.eq(nxt).addClass("num_active");
// Modulus operator method courtesy of Nick Craver (see comment below)
cur = (cur + 1)%arr.length;
nxt = (nxt + 1)%arr.length;
},6000);
Original:
I assume the num_active
is only on one element on the page at a time.
var arr = [
$("#pension"),
$("#health").hide(),
$("#billing").hide()
];
var cur = 0, nxt = 1;
setInterval(function() {
arr[cur].fadeOut(2000);
arr[nxt].fadeIn(2000);
// remove num_active class from the current one
$('#tournums .num_active').removeClass('num_active');
// add num_active class using nxt as the index
$("#tournums ul li:eq(" + nxt + ") a").addClass("num_active");
cur = (cur + 1 < arr.length) ? cur + 1 : 0;
nxt = (nxt + 1 < arr.length) ? nxt + 1 : 0;
},6000);
i don't know exactly what you want to do but I think this could help
if($("#health").attr("display") == "block")
{
$("#tournums ul li a").addClass("num_active");
}
else
{
$("#tournums ul li a").removeClass("num_active");
}
tell me what you want to do or give a link to the example at least.
精彩评论