我正在寻找一种方法,有两个单独的操作/函数/“代码块”运行时,点击了一些,然后一个完全不同的块,当同样的事情被点击了一次。是我组装的。我想知道是否有更有效/更优雅的方法。我知道 jQuery. toggle (),但是它不能按照预期的方式工作。
在这里工作: 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);
}
});