Ver Mensaje Individual
  #7 (permalink)  
Antiguo 07/10/2012, 08:58
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Imagen aleatoria en un inicio

ejecutá la función tambien onload, con lo que la imagen debiera cambiarse.
Edito:
Despiste el mío. Es lo que sugirió @Sirikon +1


Otra cosa a tener en cuenta, si hacés un ramdom y tenés solo 3 imágenes, es probable que veas varias veces la misma antes de que se produzca la rotación.

Te dejo una función para que analices, con lo que se hace el ramdom pero los numeros no se repiten

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6.  
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. //Método Fisher-Yates
  10. var mezclar = function(n){
  11. for(var j, x, i = n.length; i; j = parseInt(Math.random() * i), x = n[--i], n[i] = n[j], n[j] = x);
  12.  
  13. return n;
  14. }
  15. var sec = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  16. function mostrar(){
  17. var texto = document.getElementById('texto');
  18. var cadena = mezclar(sec).toString();
  19. if(sec.length == 1){
  20. sec = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  21. }
  22. texto.innerHTML = cadena[0];
  23. sec.shift();
  24. }
  25.  
  26. setInterval("mostrar()", 1000);
  27.  
  28. //]]>
  29. </head>
  30. <body onload="mostrar();">
  31. <span id="texto">
  32. </span>
  33. </body>
  34. </html>

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.

Última edición por emprear; 07/10/2012 a las 10:09