【发布时间】:2016-06-28 19:05:43
【问题描述】:
我现在使用 JavaScript,我想为每个 <li> 设置一个循环,设置从 n° 1 到 <li> n° 4 的类“活动”,然后每 3 秒重新开始到 n° 1。
到现在为止我都有这个代码:
HTML
<ul class="collection">
<li id="first" class="collection-item active">Desplazate hacia la pestaña <strong>HORARIOS</strong>.</li>
<li id="second" class="collection-item ">Ingresa tu N° de documento.</li>
<li id="third" class="collection-item ">Presiona el botón <strong>INGRESAR</strong>.</li>
<li id="four" class="collection-item "><strong>LISTO!</strong> Ahora puedes ver los horarios de la semana.</li>
</ul>
JavaScript
$(document).ready(function(){
setInterval(animacion,3000);
function animacion(){
$currently_selected = $('li.active')
// Loop back to first sibling if on the last one.
if ($currently_selected.next().length = 0){
$next_selected = $currently_selected.siblings().first()
} else {
$next_selected = $currently_selected.next()
$currently_selected.removeClass('active')
$next_selected.addClass('active')
}
}
});
请帮帮我!
【问题讨论】:
标签: javascript jquery loops