Estoy mostrando una serie de elementos usando la función next(). Una vez que llego al final, quiero ir al primer elemento. ¿Algunas ideas?jQuery: cómo saber cuándo next() llega al final, luego vaya al primer elemento
Aquí está el código:.
//Prev/Next Click
$('.nextSingle').click(function() {
//Get the height of the next element
var thisHeight = $(this).parent().parent().parent().next('.newsSingle').attr('rel');
//Hide the current element
$(this).parent().parent().parent()
.animate({
paddingBottom:'0px',
top:'48px',
height: '491px'
}, 300)
//Get the next element and slide it in
.next('.newsSingle')
.animate({
top:'539px',
height: thisHeight,
paddingBottom:'100px'
}, 300);
});
Básicamente necesito un "if" que dice "si no hay elementos restantes 'siguiente', y luego encontrar el primero
Gracias
!
thx patrick! Parece prometedor, pero me aparece "Error: $ ancestor.prevAll (". NewsSingle "). La última no es una función" –
@ j-man86 - ¿Qué versión de jQuery estás usando? El método '.last()' se agregó en jQuery 1.4. – user113716
@ j-man86 - Estaba a punto de hacer una edición. Dejaré un comentario en su lugar. Si necesita una versión anterior de jQuery, en lugar de 'prevAll(). Last()', podría hacer '.prevAll (': last')'. – user113716