我想做的是通过点击左右导航箭头,按照方向依次使div进入和离开屏幕。当你点击右箭头时,div就会从右到左滑动,它能正常工作。我无法找出左箭头的代码,所以div将从相反的方向从左到右滑动。这是一个例子:http://jsfiddle.net/ykbgT/6696/
还有一个问题Slide divs off screen using jQuery + added navigation arrows标记为已回答,但答案并没有给出导航箭头功能的详细说明。
下面是代码:
HTML
下面是代码:
HTML
<div class="move left">←</div>
<div class="move right">→</div>
<div id="container">
<div id="box1" class="box current">Div #1</div>
<div id="box2" class="box">Div #2</div>
<div id="box3" class="box">Div #3</div>
<div id="box4" class="box">Div #4</div>
<div id="box5" class="box">Div #5</div>
</div>
CSS
body {
padding: 0px;
}
#container {
position: absolute;
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;
}
.box {
position: absolute;
width: 50%;
height: 300px;
line-height: 300px;
font-size: 50px;
text-align: center;
border: 2px solid black;
left: 150%;
top: 100px;
margin-left: -25%;
}
#box1 {
background-color: green;
left: 50%;
}
#box2 {
background-color: yellow;
}
#box3 {
background-color: red;
}
#box4 {
background-color: orange;
}
#box5 {
background-color: blue;
}
.move{
position:fixed;
z-index:2;
top:50%;
margin-top:-20px;
text-align:center;
padding:20px;
background:#fff;
color: #000;
}
.left{
left:0;
}
.right{
right:0;
}
JAVASCRIPT
$('.right').click(function(event) {
$('.current').animate({
left: '-50%'
}, 500, function() {
$(this).css('left', '150%');
$(this).appendTo('#container');
$(this).removeClass('current');
});
$('.current').next().animate({
left: '50%'
}, 500, function (){
$(this).addClass('current');
});
});
$('.left').click(function(event) {
$('.current').animate({
left: '50%'
}, 500, function() {
$(this).css('left', '-150%');
$(this).prependTo('#container');
$(this).removeClass('current');
});
$('.current').prev().animate({
left: '-50%'
}, 500, function (){
$(this).addClass('current');
});
});