日期:2014-05-16  浏览次数:20439 次

jQuery点击按钮 css高度改变,然后再点击按钮 css恢复。望大神解决下~
本帖最后由 a442443285 于 2013-10-29 17:30:05 编辑

$(function(){
$("#case_more").click(function(){
$("#case").animate({"height":"650px"},600),
$("#case").animate({"height":"350px"},600);
});
});

这是我写的。。点了一下 然后就变了 又变回去了。。望大神解决下~

------解决方案--------------------

<style>
#case{background-color:yellow;width:100px;height:100px}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var i=0;
$("#case_more").click(function(){
i++;
if(i%2!=0){
$("#case").animate({"height":"650px"},600);
}else{
$("#case").animate({"height":"100px"},600);
}
});
})
</script>
<input type="button" id="case_more" value="change"/>
<div id="case">
</div>