I know there are plugins available out there, but I'm trying to make one of myself but before that I'm trying to understand the concept of making it as an infinite/circular carousel. Here is my jsfiddle so far.. http://jsfiddle.net/hbk35/KPKyz/3/
HTML:
<div id="carousel_wrapper">
<ul>
<li>
<div>0</div>
</li>
<li>
<div>1</div>
</li>
<li>
<div>2</div>
</li>
<li>
<div>3</div>
</li>
<li>
<div>4</div>
</li>
<li>
<div>5</div>
</li>
<li>
<div>6</div>
</li>
<li>
<div>7</div>
</li>
</ul>
</div>
<br>
<div id="buttons">
<button id="left">left</button>
<button id="right">right</button>
</div>
JS:
var container = $("#carousel_wrapper");
var runner = container.find('ul');
var liWidth = runner.find('li:first').outerWidth();
var itemsPerPage = 3;
var noofitems = runner.find('li').length;
runner.width(noofitems * liWidth);
container.width(itemsPerPage*liWidth);
$('#right').on('click',function(){
runner.animate({scrollLeft: -liWidth},1000);
});
$('#left').on('click',function(){
runner.animate({scrollLeft: liWidth},1000);
});
CSS:
div#carousel_wrapper{
overflow:hidden;
position:relative;
}
ul {
padding:0px;
margin:0px;
}
ul li {
list-style:none;
float:left;
}
ul li div {
border:1px solid white;
width:50px;
height:50px;
background-color:gray;
}
I do not want to use clone and detach method. Is there any other way to do that? Please anyone would like to guide me where I'm making mistake. I'm newbie to stack overflow and javascript/jquery also..trying to learn on my own. Forgive me I'm trying since to put my code onto the question, couldn't get neat and separate like others.
Thanks!!
Here you go: http://jsfiddle.net/KPKyz/5/
JS
CSS
Here you go an infinite. Could be done with less code for sure. http://jsfiddle.net/artuc/rGLsG/3/
HTML:
CSS:
JS: