2017-07-31 122 views
0

我想在jQuery中使用动画功能的侧边栏菜单从左侧(幻灯片)出现。尽管我搜索了堆栈溢出数据库,但仍无法使其工作。所以我需要在按下菜单按钮后以1秒的延时从左向右滑动。按下菜单按钮后jQuery侧边栏sildes按下菜单按钮后

<html> 
<head> 

<meta charset="utf-8"> 
<title>Sok-app</title> 
<link rel="stylesheet" type="text/css" href="style.css"> 
</head> 

<body> 
<div class="background-2" > 
<button id="menu_button"> <a href="#menu"> 
    &#9776; </a> </button> 
    <div class="sidebar" style="width:130px display:none"> 

    <button id="your-best-ap" >Your app</button> 
    <button id="team-history-conta" >Team</button> 
    <button id="team-history-conta" >History</button> 
    <button id="team-history-conta" >Contact</button> 
    <button id="suggest-to-a-friend" >Suggest to a friend</button> 
</div> 
</div> 
</div> 

<script> 
$(document).ready(function(){ 
    $("#menu_button").click(function(){ 
     $(".sidebar").animate({left: '412px'}); //animate margin to create slide from left animation 
    }, 1000);          //duration of animation, in milliseconds 
}); 
</script> 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
<script type="text/javascript" src="script.js"></script> 
</body> 
</html> 

回答

0

要设置时间click事件,而不是动画。而且这段代码将无法运行alert,因为我在第一句话中提到了格式错误。

更改像这样,

$(document).ready(function(){ 
    $("#menu_button").on("click",function(){ 
     $(".sidebar").animate({left: '412px', width:'toggle'},1000); 
     // duration after animate properties 
    });         
}); 

Result

希望帮助,

+0

谢谢你的回答,虽然它进一步移动(从412px宽的点和右侧),每当我按下按钮时它都在工作。 –

+0

然后让它-412 :) @SokratisV – Berkay