I am trying to implement a carousel with JQuery based on http://www.queness.com/post/923/create-a-simple-infinite-carousel-with-jquery. It allmost works OK. Only when i swipe left and right i dont get back to my initial position. By debugging i found out that the left set is not set in my ul element. The code:
Javascript
var container = $('#calendarContainer ul');
var moveWidth = container[0].clientWidth / 3;
var currentIndent = container.position().left;
if (event.type == "swipeleft") {
$('#calendarContainer ul').css('left', currentIndent - moveWidth);
}
if (event.type == "swiperight") {
$('#calendarContainer ul').css('left', currentIndent + moveWidth);
}
Html
<div id="calendarContainer" >
<ul>
<li id ="calendarDivLeft">
<fieldset id="calendarWeekGridLeft" class="ui-grid-a"></fieldset>
</li>
<li id ="calendarDiv" >
<fieldset id="calendarWeekGrid" class="ui-grid-a"></fieldset>
</li>
<li id="calendarDivRight">
<fieldset id="calendarWeekGridRight" class="ui-grid-a"></fieldset>
</li>
</ul>
</div>
CSS
#calendarContainer ul
{
width : 300%;
list-style: none;
padding:0px;
left : 0%;
position:relative;
margin: 0px;
padding: 0px;
}
#calendarContainer ul li
{
width: 33.333%;
float:left;
position:relative;
margin: 0px;
padding: 0px;
}
For example if the current left is 5 and I move left by 594px, I would expect to have a left of -589. Instead I get a get a left of 585! If I move right by 595 the left becomes 605 instead of 600.
How is this possible?
localhostwill not help us.$('#calendarContainer ul').css('left', (currentIndent - moveWidth) + 'px');