简体   繁体   English

切换div左右移动

[英]toggle div to move right/left

this is my first question on this website! 这是我在这个网站上的第一个问题! :) I am working on a website for a restaurant. :)我正在一家餐厅的网站上。 The problem is that the following part of my code is malfunctioning. 问题是我代码的以下部分出现了故障。 When clicked on the button, #menu expands towards right and stops after width=225px. 单击该按钮时,#菜单会向右扩展,并在width = 225px后停止。 But when I click the same button again, #menu contracts (width=50) and again expands (width=225)! 但是,当我再次单击同一按钮时,#menu收缩(宽度= 50)并再次展开(宽度= 225)! Please help! 请帮忙!

$("#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>

I think that jquery is having trouble with the integers use a string with px in it 我认为jquery遇到了麻烦,整数使用了带有px的字符串

$('#menu').toggle('click', function(){
    $(this).animate({width:'225px'},500);
},function(){
    $(this).animate({width:'50px'},500);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM