updated Jun 30, 2011
I answered this question when it was completely new to jquery . I have learned something since then, and after this answer was supported the other night, I looked at that answer. At first I was unsatisfied with how the next element would come in quickly, and more or less break the block. ( see here ). I believe that the appropriate way to deal with this issue was with a callback that gets called after the first switch.
updated jquery
$('li:gt(4)').css('display', 'none');
$("button").click(function() {
$('li:first').insertAfter('li:last').toggle('clip', 100, function() {
$('li:eq(4)').toggle('scale', 100);
});
});
see updated live example .
.toggle( [duration,] [easing,] [callback] )
durationA string or number determining how long the animation will run.
easingA string indicating which easing function to use for the transition.
callbackA function to call once the animation is complete.
old
JQuery
$('li:gt(4)').css('display', 'none');
$("button").click(function() {
$('li:first').fadeOut('fast').insertAfter('li:last')
$('li:eq(4)').fadeIn(); });
HTML
<ul>
<li class="slider"> Item-1 </li>
<li class="slider"> Item-2 </li>
<li class="slider"> Item-3 </li>
<li class="slider"> Item-4 </li>
<li class="slider"> Item-5 </li>
<li class="slider"> Item-6 </li>
<li class="slider"> Item-7 </li>
<li class="slider"> Item-8 </li>
<li class="slider"> Item-9 </li>
<li class="slider"> Item-10 </li>
</ul>
<button> Next > </button>
and fiddle http://jsfiddle.net/EZpMf/
It will be less rigid and use much less code. I also think it is very readable.
, , 4 ( ) . , , , 4- . , . toggle , jquery-ui. .
, . +
$('li:gt(4)').css('display', 'none');
$("button").click(function() {
$('li:first').insertAfter('li:last').toggle('clip',100);
$('li:eq(4)').toggle('scale', 100);
});
http://jsfiddle.net/67Wu7/