ago 07
Este snippet lo tenía guardado hace bastante tiempo y aun no lo había probado, y ahora lo estoy usando en una web que estoy diseñando, y como funciona a las mil maravillas pues lo comparto.
Funciona simplemente con añadir este código dentro de las etiquetas body de la web:
1
2
3
4
5
6
7
8
9
10
11
12
13
| <script language="javascript">
function RandomImage(){
n=0;
this[n++] = "img01.jpg";
this[n++] = "img02.jpg";
this[n++] = "img03.jpg";
this[n++] = "img04.jpg";
this.N=n;
}
var Imagenes = new RandomImage();
src = Imagenes[ Math.floor(Math.random() * Imagenes.N) ] ;
document.write("<img src='"+src+"'>");
</script> |
Desconozco la fuente de donde lo saqué tiempo atrás. Pero mio el código no es.
Etiquetas: diseño web • javascript • programacion
jul 16
Se que no es gran cosa, pero me hacia ilusión (y me ha costado un ratico), así que lo pongo aquí. Es muy simple si lo quieres ver funcionando pulsa aquí. Y el código es este:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| <!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>menu emergente</title>
<style type="text/css">
.oculto { display: none; }
.visible { display: inline; }
</style>
<script type="text/javascript">
function menu_emergente(){
var emer = document.getElementById("items");
if(emer.getAttribute('class') == "oculto"){
emer.setAttribute("class","visible");
}else{
//emer.setAttribute("class","oculto");
fuera_menu();
}
}
function fuera_menu(){
var emer = document.getElementById("items");
emer.setAttribute("class","oculto");
}
</script>
</head>
<body>
<a id="menu" href="#" onclick="menu_emergente()" >Menu</a>
<div id="items" class="oculto" onclick="fuera_menu()">
<br /><a href="http://google.es" target="_blank">elemento1</a>
<br /><a href="http://elpais.es" target="_blank">elemento2</a>
<br /><a href="http://k40s.org" target="_blank">elemento3</a>
<br /><a href="http://publico.es" target="_blank">elemento4</a>
<br /><a href="./">elemento5</a>
</div>
</body>
</html> |
Etiquetas: css • desarrollo • html • javascript • programacion