慕仙森
用hasClass/addClass/removeClass或attr标记状态实现toggle切换<button id="animate" status="0">animate</button><div id="block">Hello World</div>$("#animate").click(function(){ if(!$(this).hasClass("clicked")) { $(this).addClass("clicked"); $("#block").animate({"font-size": "10em"}, 1000, "linear", function(){console.log("complete");}); } else { $(this).removeClass("clicked"); $("#block").animate({"font-size": "1em"}, 1000, "linear", function(){console.log("complete");}); }});$("#animate").click(function(){ if($(this).attr("status") == 0) { $(this).attr("status", 1); $("#block").animate({"font-size": "10em"}, 1000, "linear", function(){console.log("complete");}); } else { $(this).attr("status", 0); $("#block").animate({"font-size": "1em"}, 1000, "linear", function(){console.log("complete");}); }});