function expand(div_block_id, expansion_class, original_class, time, callback_function_original, callback_function_expand) {
console.log("entered expand");
var id = '#' + div_block_id; //ID received by function
counter = counters[div_block_id + '_counter']; //Associates the counter per div block respectively
//Original ID of style
$(id).click(function () {
console.log("entered expand on click");
//If the click counter is even then animate back to original state
$("#dialog").remove();
console.log(counter);
if (++counter % 2 == 0) {
console.log('counter =>'+counter);
console.log('counter array index value ='+ counters[div_block_id + '_counter']);
counters[div_block_id + '_counter'] = counter;
console.log("entered expand if");
$(this).animate(original_class, {
duration: time, //animation duration
start: callback_function_original //make animation happen symultaneously with callback
});
console.log("animated original class");
console.log(counters);
} else {
//++counter;
counters[div_block_id + '_counter'] = counter;
console.log("entered expand else");
//Expand to desired css
$(this).animate(expansion_class, {
duration: time,
start: callback_function_expand //make animation happen symultaneously with callback
});
console.log("animated expand class");
console.log(div_block_id + '=' + counters[div_block_id + '_counter']);
//Reset counter on every uneven click so it wont get bigger
//counters[div_block_id + '_counter'] = 0;
}
console.log("exited expand");
});
};
}
我有一个基本的if else情况,它假设检测偶数和奇数点击
$(id).click(function(){
if(++counter % 2 == 0){
...add some animations
}else{
do some other animation
}
但是当我打开两个或更多个div时,计数器会失去计数,但是当我看到控制台时,数组会显示出来。我想要做的就是点击任何div,如果主div打开然后你可以展开那个div,但如果你关闭主div与其他div打开所有它们应该关闭。
我知道得到它有点难,你可以看到这个fiddle