123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <h1>Luciérnagas volando. CSS + JS. </h1>
<div id="capa"></div>
<footer>Para <a target="_blank" href="https://escss.blogspot.com/2017/02/revision-posts-nuevas-demos.html">EsCss</a>. </footer>

            
          
!
            
              body {
height: 90vh; 
background-color: #000; 
background-image: url(https://2.bp.blogspot.com/-84F3YvIAUvw/V-pfeoyFaXI/AAAAAAAANPc/Y4nYWBfGS0E5lyzC6gEvyCyG4hLhBk9wwCLcB/s1600/night-Martin_Str_Pixabay.jpg); 
background-size: 100% auto; 
background-position: center bottom; 
background-repeat: no-repeat; 
}

h1 {
width: 16em; 
margin: 20px auto; 
padding: .2em .15em; 
color: thistle; 
background-color: rgba(255,255,255,.3); 
text-align: center; 
border-radius: 1em; 
box-shadow: 0 0 .4em 0 rgba(255,255,255,.5); 
}

#capa {
position: fixed; 
top: 0; left: -10vw; 
height: 100vh; 
width: 120vw; 
pointer-events: none; 
}

.lux_i , .lux_d {
position: absolute; 
top: 10vh; left: -1em; 
width: 1em; height: .8em; 
border-style: solid; 
border-width: 0 .35em; 
border-color: black transparent black gold; 
border-radius: 90%; 
background: 
radial-gradient(transparent 40%, dimgrey 70%, transparent 70%) 0 .1em, 
radial-gradient(yellow 60%, transparent 70%) 1.15em .3em, 
radial-gradient(transparent 40%, dimgrey 70%, transparent 70%) 0 .3em, 
radial-gradient(yellow 60%, transparent 70%) -.25em .3em, black; 
background-size: 100% 50%, .14em .14em; 
background-repeat: no-repeat; 
box-shadow: -.2em 0 .2em 0 yellow; 
transition: top 5s ease-in-out, left 5s ease-in-out;
}

.lux_d {
border-color: black gold black transparent; 
background: 
radial-gradient(transparent 40%, dimgrey 70%, transparent 70%) 0 .1em, 
radial-gradient(yellow 60%, transparent 70%) 1.15em .3em, 
radial-gradient(transparent 40%, dimgrey 70%, transparent 70%) 0 .3em, 
radial-gradient(yellow 60%, transparent 70%) -.25em .3em, black; 
background-size: 100% 50%, .14em .14em; 
background-repeat: no-repeat; 
box-shadow: .2em 0 .2em 0 yellow; 
}
.lux_i::before , .lux_d::before {
content: ""; 
position: absolute; 
top: .1em; left: 0; 
width: 1em; height: .4em; 
box-shadow: 0 0 .18em .07em silver, inset 0 0 .18em .07em silver; 
border-radius: 90%; 
animation: vuela 150ms infinite; 
}

@keyframes vuela {
0% {top: 0; }
100% {top: .3em; }
}

footer {
position: absolute; 
bottom: 20px; right: 10px; 
font-size: 120%; 
font-weight: bold; 
padding: .2em .15em; 
color: thistle; 
background-color: rgba(255,255,255,.3); 
text-align: center; 
border-radius: 1em; 
box-shadow: 0 0 .4em 0 rgba(255,255,255,1); 
}

a {
color: inherit; 
}

            
          
!
            
              /* CARGA LA FUNCIÓN DE INICIO */
onload = inicia; 

var cantidadBichos = 6; //CANTIDAD MÁXIMA DE BICHOS EN PANTALLA 

function inicia() {
  /* CREA LOS BICHOS */
  for(c=0; c<cantidadBichos; c++) {
    /* UN DIV PARA CADA UNO */
    bicho = document.createElement("div"); 
    /* LES DA LA CLASE lux_i (INICIAN TODOS VOLANDO DESDE IZQUIERDA) */
    bicho.setAttribute("class", "lux_i"); 
    /* ASIGNA UN ATRIBUTO PARA GUARDAR LA COORDENADA X EN CADA VUELTA */ 
    bicho.setAttribute("data-origen", "0"); 
    /* PONE EL DIV EN LA CAPA CONTENEDORA */
    document.getElementById("capa").appendChild(bicho); 
  }

  /* REFERENCIA A LA COLECCIÓN ACTUAL DE BICHOS (TODOS .lux_i) */
  var losBichos = document.querySelectorAll("#capa .lux_i"); 

  /* LOS RECORRE PARA ASIGNAR UN EVENTO transitionend Y SU FUNCIÓN */
  for(t=0; t<cantidadBichos; t++) {
    losBichos[t].addEventListener("transitionend", function(){vuela(this)}, false); 
    //losBichos[t].innerHTML = t;
  }

  /* EJECUTA CON RETARDO 100ms LA FUNCIÓN vuela() PARA CADA DIV */
  setTimeout(function(){
    for(c=0; c<cantidadBichos; c++) {
    vuela(losBichos[c]);
    }
  }, 100);
}

/* ANIMACIÓN ALEATORIA */
function vuela(T) {
  /* PIXELES PARA NUEVA POSICIÓN X */
  var posIzq = Math.floor(Math.random()*120); 
  /* COMPARA CON POSICIÓN ANTERIOR PARA SABER SI SE MUEVE MÁS A IZQUIERDA O DERECHA (ORIGINALMENTE CADA data-origen ES 0) Y GUARDA LA CLASE PARA QUE MIRE HACIA UN LADO O EL OTRO */
  var dir = (T.dataset.origen < posIzq)? "lux_i" : "lux_d"; 
  /* REESCRIBE data-origen CON LA NUEVA POSICIÓN REAL */
  T.dataset.origen = parseInt(T.style.left); 
  /* ASIGNA LA CLASE A CADA DIV */
  T.className = dir; 

  /* ASIGNA UN TIEMPO DE VUELO AL AZAR DE 3 A 11 SEGUNDOS */
  T.style.transitionDuration = (Math.floor(Math.random()*8000) + 3000)+ "ms"; 
  /* MUEVE A LA NUEVA COORDENADA X */
  T.style.left = posIzq + "vw"; 
  /* MUEVE A UNA COORDENADA Y AL AZAR DENTRO DEL VIEWPORT */
  T.style.top = Math.floor(Math.random()*100)+ "vh"; 
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console