【发布时间】:2014-10-10 15:20:00
【问题描述】:
我正在尝试创建一个带有 2 个按钮的 div。单击第一个按钮,另一个 div 从左侧滑入。它有一个按钮,点击后会滑出屏幕。与主 div 中的第二个按钮相同。仅当单击第二个按钮时,div 才会从右侧滑入。再次使用一个按钮,使其滑出屏幕。
这一切都在 jquery 中完成。
谁能告诉我这里出了什么问题?
jquery:
var boxWidth = $("#port2").width();
$('#left').on('click',function(){
$('#port1').animate({left:'8'});
});
$('#right').on('click',function(){
$('#port2').animate({(right:'100%'-boxWidth});
})
$('#leftC').on('click',function(){
$('#port1').animate({right:'100%'});
});
$('#rightC').on('click',function(){
$('#port2').animate({left:'100%'});
});
html:
<div id="wrapper">
<div id="port1">
Left text goes here
<button id='leftC'>Close 1</button>
</div>
<div id="port2">
Right text goes here
<button id='rightC'>Close</button>
</div>
<div id="text">
good stuff goes here
<br />
<button id='left'>Left</button>
<br />
<button id='right'>Right</button>
</div>
</div>
css
#text{
width:500px;
height:200px;
background-color:red;
font-weight:bold;
font-size:1.2em;
padding:25px;
}
#text button{
margin: 20px 0px 10px;
}
#port1{
width:500px;
height:200px;
background-color:green;
font-weight:bold;
font-size:1.2em;
padding:25px;
position:absolute;
left:-100%
}
#port2{
width:500px;
height:200px;
background-color:yellow;
font-weight:bold;
font-size:1.2em;
padding:25px;
position:absolute;
right:-100%;
}
您可以在这里看到它的实际效果: http://jsfiddle.net/belotte/vmu59h87/19/
谢谢
【问题讨论】:
标签: javascript jquery html jquery-animate