Ver Mensaje Individual
  #3 (permalink)  
Antiguo 05/06/2012, 22:44
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: Creación código para poner 3 imágenes aleatoria

En primer lugar, bienvenido a FDW @eraseunavezconvos

Te voy a tirar unas pistas a ver a dónde llegás, hace poco tiempo atrás (justamente mi colega @furoya tomo parte del experimento) hice esto, (que en realidad no sé bien para que sirve)
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>Números aleatorios únicos en botones</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <style type="text/css">
  7. /*<![CDATA[*/
  8. input[type='button']{
  9. width: 50px;
  10. height: 50px;
  11. padding: 2px 4px 2px 2px;
  12. margin: 1px;
  13. border-radius: 5px;
  14. border: solid #4A2626 2px;
  15. background-color: #793E3E;
  16. font-style: italic;
  17. font-weight: bold;
  18. text-shadow: 1px 1px 0px #B2B2B2;
  19. cursor:pointer;
  20. font-size:14pt;
  21. outline:none;
  22. }
  23. input[type='button']:hover{
  24. color: #F27B24;
  25. text-shadow: 1px 1px 0px #000;
  26. padding: 0px;
  27. border: ridge #000 3px;
  28. }
  29. #visor {
  30. width: 152px;
  31. height: 40px;
  32. line-height: 40px;
  33. font-size: 26px;
  34. color:#5A2E2E;
  35. padding-left: 8px;
  36. font-family: arial, serif;
  37. border: dotted 1px #5A2E2E;
  38. cursor: none;
  39. }
  40. .botones{
  41. margin-top: 15px;
  42. cursor: default;
  43. display: inline-block;
  44. }
  45. /*  código para el Tooltip  */
  46. .tip {
  47. position: relative;
  48. border-bottom: dotted 1px #3E3E3E;
  49. cursor: default;
  50. }
  51. .tip span {
  52. display: none;
  53. position: absolute;
  54. top: 15px;
  55. left: 20px;
  56. width: 150px;
  57. padding: 5px;
  58. z-index: 100;
  59. background: #000;
  60. color: #fff;
  61. border-radius: 5px;
  62. -moz-border-radius: 5px; /* Firefox */
  63. -webkit-border-radius: 5px; /* Safari */
  64. font-family: arial, serif;
  65. font-size: 12px;
  66. text-align: center;
  67. }
  68. *:hover.tip {
  69. font-size: 99%; /* fix IE */
  70. }
  71. *:hover.tip span {
  72. display: block;
  73. margin-left: 0px;
  74. margin-top: 30px;
  75. }
  76. /*]]>*/
  77. <script type="text/javascript">
  78. //<![CDATA[
  79. //Método Fisher–Yates
  80. var mezclar = function(n){
  81. for(var j, x, i = n.length; i; j = parseInt(Math.random() * i), x = n[--i], n[i] = n[j], n[j] = x);
  82. return n;
  83. }
  84. //]]>
  85. <script type="text/javascript">
  86. //<![CDATA[
  87. function escribe_numeros(r){
  88. var sec = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  89. var cadena = mezclar(sec).toString();
  90. var numeros = new Array();
  91. numeros=cadena.split(",");
  92. var f = 0;var m;
  93. for (m=0;m<numeros.length;m++){
  94. var campo = 'b_' + f;
  95. document.getElementById(campo).disabled = false;
  96. if(r != 'no'){document.getElementById(campo).value = numeros[m];}f++;}
  97. document.getElementById('visor').value = "";
  98. }
  99. function rellenar(v,idc){
  100. var c=document.getElementById("visor").value;
  101. c=c+v;
  102. document.getElementById("visor").value= c;
  103. document.getElementById(idc).disabled = true;
  104. }
  105. function reiniciar(r){
  106. document.getElementById("visor").value= '';
  107. r=(r=='si')?escribe_numeros():escribe_numeros('no');
  108. }
  109. //]]>
  110. </head>
  111. <body onload="escribe_numeros();">
  112. <div style="margin-top: 20px;">
  113. <form action="#">
  114. <div><input type="text" value="" readonly="readonly" id="visor" maxlength="10"
  115.     onmouseout="this.style.color='#5A2E2E'" onmouseover="this.style.color='#FFF'"/></div>
  116. <div class="botones">
  117. <input type="button" onclick="rellenar(this.value,this.id);" value="1" id="b_1" /> <input type="button" onclick="rellenar(this.value,this.id);" value="2" id="b_2" /> <input type="button" onclick="rellenar(this.value,this.id);" value="3" id="b_3" /> <br />
  118. <input type="button" onclick="rellenar(this.value,this.id);" value="4" id="b_4" /> <input type="button" onclick="rellenar(this.value,this.id);" value="5" id="b_5" /> <input type="button" onclick="rellenar(this.value,this.id);" value="6" id="b_6" /> <br />
  119. <input type="button" onclick="rellenar(this.value,this.id);" value="7" id="b_7" /> <input type="button" onclick="rellenar(this.value,this.id);" value="8" id="b_8" /> <input type="button" onclick="rellenar(this.value,this.id);" value="9" id="b_9" /> <br />
  120. <input type="button" onclick="rellenar(this.value,this.id);" value="0" id="b_0" /> <span class="tip"><input type="button" onclick="reiniciar();" value="C" /><span>Restablece a cero<br />y conserva los números actuales</span></span>
  121. <span class="tip" id="rei_si"><input type="button" onclick="reiniciar('si');" value="R" /><span>Restablece a cero<br />y genera una nueva secuencia</span></span>
  122. </div>
  123. </form>
  124. </div>
  125. </body>
  126. </html>

visto así seguramente te confunde más de lo que te aclara (si lo ejecutás te parecerá muy atractivo, pero no mucho más que eso)

Si te fijás al inicio hay una función llamada mezclar(), que es un poco el secreto del resto. Esa función es posteriormente invocada en la función escribe_numeros(); y lo que hace es 'mezclar' aleatoriamente los números del array sec.
Si mal no recuerdo el mazo de cartas de tarot tiene 78 cartas, con lo que deberías llamas a tus imágenes del 1 al 78 con la extensión jpg, por ejemplo. Como las funciones te muestran por resultados números, a la hora de mostrarlos, tu html generado tendrá que ser algo como

'<img src="' + variable_javascript + '.jpg" width="xxx" height="xxx" alt="" />

Bueno, investigá un poco más, desmenuzá la script y fijate a dónde llegás, después volvés a consultar, probablemente, terminemos haciendo tu código, no sin antes hacerte romper la cabeza un poquito y quitarte algunas horas de sueño...

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