Foros del Web » Programando para Internet » Javascript »

AYuda Con fondo aleatorio

Estas en el tema de AYuda Con fondo aleatorio en el foro de Javascript en Foros del Web. alguien me puede decir que script puedo usar para que cada vez que toke f5 cambie el fondo de mi pagina porque eh buscado pero ...
  #1 (permalink)  
Antiguo 29/01/2011, 18:07
 
Fecha de Ingreso: diciembre-2010
Mensajes: 19
Antigüedad: 13 años, 4 meses
Puntos: 0
AYuda Con fondo aleatorio

alguien me puede decir que script puedo usar para que cada vez que toke f5 cambie el fondo de mi pagina porque eh buscado pero no encuentro alguna solucion

aki dejo el html


Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Documento sin t&iacute;tulo</title>
<
link href="stylo.css" rel="stylesheet" type="text/css" />
</
head>





<
body>
<
p><img id="Bg"  src="3.jpg"/></p>
<
div id="Site">
<
div id="menu">
</
div>

</
div>
</
div>


</
body>
</
html
y aki dejo el css

Código PHP:
/* CSS Document */
html,body{margin:0;padding:0;height:100%;overflow:hidden;}
#Bg,#Site{
    
position:absolute;
    
z-index:-1;
    
width:100%;
    
height:100%;
    
left: -1px;
    
top: -2px;
}
#Site{z-index:1;overflow:auto;color:#fff;}
#Content{width:800px;margin:auto;}    
#menu {float:right; background-image:url(fmenu.png); background-repeat: no-repeat; height:150px; width:300px; margin-top:200px; margin-right:10px;} 

desde ya muchas gracias
  #2 (permalink)  
Antiguo 29/01/2011, 20:59
 
Fecha de Ingreso: enero-2011
Ubicación: Cali
Mensajes: 73
Antigüedad: 13 años, 3 meses
Puntos: 2
Respuesta: AYuda Con fondo aleatorio

Saludos...

Intenta en

http://www.forosdelweb.com/f13/fondos-aleatorios-para-mi-web-como-ayuda-486952/

Hay aparece un códgio que puede funcionarte y fue tratado en este foro.

Última edición por gcrlink; 29/01/2011 a las 21:01 Razón: la opción de insertar enlace no me funcionó
  #3 (permalink)  
Antiguo 29/01/2011, 21:52
 
Fecha de Ingreso: diciembre-2010
Mensajes: 19
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: AYuda Con fondo aleatorio

me podrias sitar un ejemplo con mi codigo porque no eh entendido bien como modificar
  #4 (permalink)  
Antiguo 29/01/2011, 23:03
 
Fecha de Ingreso: enero-2011
Ubicación: Cali
Mensajes: 73
Antigüedad: 13 años, 3 meses
Puntos: 2
Respuesta: AYuda Con fondo aleatorio

Cita:
Iniciado por lukkifrag Ver Mensaje
me podrias sitar un ejemplo con mi codigo porque no eh entendido bien como modificar
Hola... el Código que presenta sirguy en el post es sencillo de utilizar. Sólo tienes que copiarlo tal cual está en la cabecera de tu código HTML, o sea entre las etiquetas <head></head> de la siguiente manera:

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Documento sin t&iacute;tulo</title>
  5. <link href="stylo.css" rel="stylesheet" type="text/css" />
  6.  
  7.  
  8. <!-- INICIO DEL CÓDIGO -->
  9.  
  10. <script type="text/javascript">
  11. <!--
  12. /*Random Background Image-
  13. By JavaScript Kit (www.javascriptkit.com)
  14. More free JavaScripts here!
  15. */
  16.  
  17. var backgr1="../clip/backgr4.jpg"
  18. var backgr2="../clip/backgr17.jpg"
  19. var backgr3="../clip/backgr13.jpg"
  20.  
  21. var cur=Math.round(6*Math.random())
  22. if (cur<=1)
  23. backgr=backgr1
  24. else if (cur<=4)
  25. backgr=backgr2
  26. else
  27. backgr=backgr3
  28. document.write('<body background="'+backgr+'" bgcolor="#FFFFFF">')
  29. // -->
  30.  
  31. <!-- FIN DEL CÓDIGO -->
  32.  
  33.  
  34. </head>
  35.  
  36.  
  37. </body>
  38. </html>


Luego debes sustituir el valor de cada una de las variables (lo que está en verde) var backgr1="../clip/backgr4.jpg" por la ruta de la imágen que quieras que se muestre cada vez que reinicias la página con F5. Puedes incluir el número de imágenes o fondos que desees. Sólo debes incluir la misma variable cambiando el número que tiene al final por EJ.

Código:
var backgr1 = mi images.png
var backgr2 = mi images.png
var backgr3 = mi images.png
var backgr4 = mi images.png
var backgr5 = mi images.png
var backgr6 = mi images.png

etc...
En el ejemplo que te pongo te borré el código que habías escrito entre <body></body> porque para que este script funcione no hacía falta. Entendiendo que lo que deseas es que cada vez que el usuario visite la página se vea un fondo diferente.

Espero te funcione.

Última edición por gcrlink; 29/01/2011 a las 23:40
  #5 (permalink)  
Antiguo 30/01/2011, 08:24
 
Fecha de Ingreso: diciembre-2010
Mensajes: 19
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: AYuda Con fondo aleatorio

perfecto ahora mismo lo estoy probando y te comento que tal me ha ido
  #6 (permalink)  
Antiguo 30/01/2011, 09:02
 
Fecha de Ingreso: diciembre-2010
Mensajes: 19
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: AYuda Con fondo aleatorio

me ha funcionado pero no logro poner mas de 3 images , me podrias decir como poner mas ? por favor
  #7 (permalink)  
Antiguo 30/01/2011, 09:29
Avatar de _cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 11 meses
Puntos: 310
Respuesta: AYuda Con fondo aleatorio

Sinceramente, creo que ese código es más bien poco útil. Prueba este:
Código Javascript:
Ver original
  1. var fondos = ['img1.jpg', 'img2.gif', 'img3.png']; // Aquí pon la url de todos los fondos
  2. var rnd = Math.floor(Math.random()*fondos.length);
  3. document.body.style.backgroundImage = fondos[rnd];
Saludos (:
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red
  #8 (permalink)  
Antiguo 30/01/2011, 10:11
 
Fecha de Ingreso: diciembre-2010
Mensajes: 19
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: AYuda Con fondo aleatorio

no lo he podido editar porque me dice enlace no valido asi que nuevante respondo

eh probado tu codigo pero no me ha funcionado , me puedes decir cual es mi error ?

aka dejo mi html

Código PHP:
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Documento sin t&iacute;tulo</title>
<
link href="stylo.css" rel="stylesheet" type="text/css" />
</
head>
<!-- 
INICIO DEL CÓDIGO -->
 

<
script type="text/javascript">
var 
fondos = ['/paisajes/1.jpg''paisajes/2.jpg''paisajes/3.jpg''paisajes/4.jpg''paisajes/5.jpg''paisajes/6.jpg''paisajes/7.jpg''paisajes/8.jpg']; 
var 
rnd Math.floor(Math.random()*fondos.length);
document.body.style.backgroundImage fondos[rnd];

</script> 






<body>


<div id="Site">
<div id="Content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scras, and more recently with desktop publishing software like Aldus PageMaker includrinting and typesetting industry. Lorem Ipsum has been the industry's standard dummy ecently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
<div id="menu">



</div>
</div>


</body>
</html> 
  #9 (permalink)  
Antiguo 30/01/2011, 10:31
Avatar de _cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 11 meses
Puntos: 310
Respuesta: AYuda Con fondo aleatorio

Mueve el script dentro del body.
Saludos (:
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red
  #10 (permalink)  
Antiguo 30/01/2011, 11:20
 
Fecha de Ingreso: diciembre-2010
Mensajes: 19
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: AYuda Con fondo aleatorio

sige sin funcionar ...
  #11 (permalink)  
Antiguo 30/01/2011, 11:34
Avatar de _cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 11 meses
Puntos: 310
Respuesta: AYuda Con fondo aleatorio

Ahora sí funciona, me dejé una parte de código XD
Código Javascript:
Ver original
  1. document.body.style.backgroundImage = 'url('+fondos[rnd]+')';
Saludos (:
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red
  #12 (permalink)  
Antiguo 30/01/2011, 11:46
 
Fecha de Ingreso: diciembre-2010
Mensajes: 19
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: AYuda Con fondo aleatorio

ahora se muchas gracias por la ayuda recibidia

Etiquetas: fondo, aleatoria
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:46.