我正在寻找一种方法,有两个独立的操作/函数/"代码块"被单击时运行,然后当同样的事情再次被单击时,运行一个完全不同的挡路.我把这些放在一起.我想知道有没有更有效/更优雅的方式.我知道jQuery .toggle(),但它有点糟糕.
Working here: http://jsfiddle.net/reggi/FcvaD/1/
var count = 0;
$("#time").click(function() {
count++;
//even odd click detect
var isEven = function(someNumber) {
return (someNumber % 2 === 0) ? true : false;
};
// on odd clicks do this
if (isEven(count) === false) {
$(this).animate({
width: "260px"
}, 1500);
}
// on even clicks do this
else if (isEven(count) === true) {
$(this).animate({
width: "30px"
}, 1500);
}
});