I am trying to make sliding DIVs.
I succeeded to make 1st DIV to go to 2nd DIV and vice versa. However, I could not make 2nd DIV slide to 3rd DIV.
The code is as follow :
$(function(){
var slideW = $('#slides').width();
// Next slide
$('#next-slide').click(function( e ){
e.preventDefault();
$('#slides').animate({scrollLeft: slideW}, 600);
});
//previous slide
$('#back-slide').click(function( e ){
e.preventDefault();
$('#slides').animate({scrollLeft: -slideW }, 600);
});
});
#slides{
position:relative;
overflow:hidden;
margin:0 auto;
background:#cf5;
width:100%;
height:200px;
white-space:nowrap;
}
#slides div{
position:relative;
display:inline-block;
margin-right:-4px;
white-space:normal;
vertical-align:top;
*display:inline;
background:#eee;
width:100%;
height:200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slides">
<div>
Content 1
<a href="#" id="next-slide">Show Content 2 .. it works!</a>
</div>
<div>
Content 2
<a href="#" id="back-slide">Show Content 1 .. it works!</a>
<br>
<a href="#" id="next-slide">Show Content 3 .. not working!!</a>
</div>
<div>
Content 3
<a href="#" id="back-slide">Show Content 2 .. not working!!</a>
</div>
</div>