切换div向左/向右移动
问题描述:
这是我在这个网站上的第一个问题! :) 我正在为一家餐厅的网站工作。问题是我的代码的以下部分出现故障。当点击按钮时,#menu向右扩展并在width = 225px之后停止。但是当我再次点击相同的按钮时,#menu合同(宽度= 50)并再次展开(宽度= 225)! 请帮忙!切换div向左/向右移动
$("#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>
答
我认为jQuery是有麻烦的整数使用字符串PX它
$('#menu').toggle('click', function(){
$(this).animate({width:'225px'},500);
},function(){
$(this).animate({width:'50px'},500);
});
你想做什么就做什么?不幸的是,我们并不介意读者。 – coreyward 2011-01-23 01:04:28
问候!您可能想通过单击“{}”图标来使用代码示例,以便首先格式化代码。 – limc 2011-01-23 01:05:08