Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

display none y display block infinito con javascript

window.onload = function() {
function mostrar(el, time,infi=false) {
    let p = document.querySelectorAll(el);
    let i = 0;
    // ejecutamos un intervalo de tiempo para los elementos
    let interval = setInterval(() => {
        // validamos que no sea el elemento 0 para aplicarle el none al anterior!
        if (i != 0)p[i - 1].style.display = "none";
        //validamos si es igual al lenght para finalizar el bucle
        if (i == p.length) {
              //retornamos i a 0
              i=0;
            // limpiamos el intervalor para que no se ejecute mas si no es infinito
            
            // retornamos para finalizar la funcion
            return;
        }
        // aplicamos el display block
        p[i].style.display = "block";
        // aumentamos i en 1
        i++;
    }, time)
}

mostrar('main div[id^="contenido"]', 2000);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: promise syntax in js 
Javascript :: node http 
Javascript :: ngif react 
Javascript :: default in javascript 
Javascript :: axios delete set content type 
Javascript :: postgresql jsonb remove key 
Javascript :: send data with emit angular 
Javascript :: java script example 
Javascript :: create array of numbers javascript 
Javascript :: js pass data between pages 
Javascript :: string to svg react 
Javascript :: mail testing 
Javascript :: start button js 
Javascript :: npm ERR! code EPERM 
Javascript :: regex check for anchor tag with specific text 
Javascript :: how to extract text from image using javascript 
Javascript :: vue add watcher 
Javascript :: calling anonymous function while declaring it 
Javascript :: visual studio node.js mac 
Javascript :: angular material moduel 
Javascript :: add property to object javascript 
Javascript :: spread and rest operator javascript 
Javascript :: Get Parameters Of URL As A String 
Javascript :: jest write test for function 
Javascript :: Send Data Using Express With Post 
Javascript :: javascript, dynamic variable, and function to add data to O 
Javascript :: local forage 
Javascript :: list of string angular 
Javascript :: use excel in js 
Javascript :: handling transaction in sequelize 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =