Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    ciclo che non si ripete

    Salve, vorrei sapere come mai questo ciclo non si ripete, si avvia una sola volta:
    codice:
    function stars() {}
    
    stars = new stars();
    number = 0;
    
    stars[number++] = document.getElementById('div1');
    stars[number++] = document.getElementById('div2');
    stars[number++] = document.getElementById('div3');
    
    var n = Math.floor(Math.random() * number);
    
    for (i=0;i<20;i++) {
    stars[n].style.opacity="1";
    }
    Grazie, buon fine settiman a!!

  2. #2
    Utente di HTML.it L'avatar di carlomarx
    Registrato dal
    Oct 2009
    Messaggi
    1,669
    E chi t'ha detto che non si ripete???
    Tutto ciò che fai con jQuery puoi farlo meglio e con la metà del codice in puro JavaScript.

  3. #3
    ho risolto così:

    codice:
    setInterval(function() { var n = Math.floor(Math.random() * number);          stars[n].style.opacity="1";         setTimeout(function(){             stars[n].style.opacity="0.1";         },500); },1000)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.