这是我在这个网站上的第一个问题! :) 我正在一家餐馆的网站上工作。问题是我的代码的以下部分出现故障。单击按钮时,#menu向右扩展并在width = 225px后停止。但是当我再次点击同一个按钮时,#menu收缩(宽度= 50)并再次展开(宽度= 225)! 请帮忙!
$("#menu").toggle(
function(){
$("#menu").animate({width:225},"slow");
},
function(){
$("#menu").animate({width:50},"slow");
});
});
});
<!--following is the code for menu-->
<div id="menu" style="position:absolute; width:50;
opacity:.4; height:75%; background-color:#000000; left:80%; top:20%;">
<button>Cart</button>
</div>
答案 0 :(得分:0)
我认为jquery在使用带有px的字符串时整数有问题
$('#menu').toggle('click', function(){
$(this).animate({width:'225px'},500);
},function(){
$(this).animate({width:'50px'},500);
});