Mostrando entradas con la etiqueta HTML. Mostrar todas las entradas
Mostrando entradas con la etiqueta HTML. Mostrar todas las entradas

sábado, 21 de abril de 2012

Rich Snippets. Introducción y ejemplo

Los "rich snippets" (fragmentos enriquecidos) son líneas de texto que aparecen debajo de cada resultado de búsqueda. La forma más clara de verlo, es con un ejemplo. Buscamos, por ejemplo, una receta (arroz con leche) y algunos de los resultados que aparecen son estos:


Uno de los resultados, el que está rodeado, vemos que tiene una línea en la que aparece la valoración de la receta, el número de opiniones y la duración de la misma. Esto es un fragmento enriquecido.

Para obtener un fragmento enriquecido debemos seguir estos pasos:
  1. Elegir un formato de marcado:
    • Microdatos
    • (recomendado por Google). A mí me ha parecido el más sencillo, ya que sólo tienes que añadir algunos atributos a las etiquetas html (normalmente, <span> o <div>).
    • Microformatos.
    • RDFa.
  2. Marcar el contenido. Google ofrece fragmentos enriquecidos para estos tipos. Pero en schema.org, puedes encontrar muchos más y también son comprendidos por Google, entre otros buscadores.
  3. Probar el marcado. Google ofrece una herramienta para probar tus fragmentos enriquecidos. De esta manera te puedes asegurar de que Google puede leer los datos marcados.
Si después de haber marcado tu sitio web y haber esperado algunas semanas, los fragmentos enriquecidos siguen sin aparecer en el buscador, puedes visitar este enlace.

PRUEBA - Persona (contacto)
Voy a hacer una prueba para el tipo de dato "persona" que ofrece Google, que puede tener las siguientes propiedades:
  • name (nombre).
    • LISA MARIE SIMPSON
  • nickname (apodo).
    • LISA
  • photo (foto).
  • title (cargo de la persona).
    • ESTUDIANTE
  • role (función de la persona).
  • url (enlace a una página web).
  • affiliation (nombre de una organización a la que está afiliada la persona).
    • ESCUELA PRIMARIA DE SPRINGFIELD
  • friend (identifica una relación social entre la persona descrita y otra).
    • MILHOUSE
  • contact (identifica una relación social entre la persona descrita y otra).
  • acquaintance (identifica una relación social entre la persona descrita y otra).
  • address (dirección de la persona).
    • street-address
      • EVERGREEN TERRACE, 742
    • locality
      • SPRINGFIELD
    • region
    • postal-code
    • country-name
      • USA
CÓDIGO
<div itemscope itemtype="http://data-vocabulary.org/Person">
  <img src="http://mickydenys.galeon.com/images/dibu4.gif" itemprop="photo" />
  Soy <span itemprop="name">Lisa Marie Simpson</span>, 
  pero todos me llaman <span itemprop="nickname">Lisa</span>.
  Esta es la web de mi familia: 
  <a href="http://www.thesimpsons.com/" itemprop="url">LOS SIMPSON</a>.
  Vivo en la calle 
  <span itemprop="address" itemscope itemtype="http://data-vocabulary.org/Address">
    <span itemprop="street-address">Evergreen Terrace, 742</span> en
    <span itemprop="locality">Springfield</span>, 
    <span itemprop="country-name">USA</span> 
  </span>
    y soy <span itemprop="title">estudiante</span>
  en la <span itemprop="affiliation">Escuela Primaria de Springfield</span>
  Mi amigo es:
   <a href="http://www.milhouse.com" rel="friend">Milhouse</a>
</div>

En la primera línea encontramos los atributos "itemscope" e "itemtype", incluidos en el <div>. "itemscope" indica que el contenido del <div> describe un elemento y con "itemtype" definimos de qué tipo de elemento se trata, en este caso, una persona. En ese <div> se describen las propiedades de la persona, para ello, a los elementos que contengan alguna de esas propiedades se les añade la etiqueta "itemprop", indicando la propiedad correspondiente, por ejemplo: <span itemprop="title">.

Si nos fijamos en la descripción de la dirección, propiedad "address", vemos que se trata de otro elemento. Es decir, un elemento puede, a su vez, estar formado por otros elementos.

RESULTADO DE LA PRUEBA DEL MARCADO


Podemos ver que en la tercera línea salen algunos de los datos que habíamos indicado y así es como se mostraría el resultado en un buscador. También cabe destacar que no se muestran todos los datos que hemos etiquetado, como por ejemplo la foto. Supongo que el buscador determina, en función del tipo que hayamos elegido y de las propiedades que le hayamos indicado, los datos que muestra.

viernes, 23 de marzo de 2012

Curiosidades - Canvas (HTML)

Hola,

hoy os dejo una entrada diferente. Un enlace a una página en la que puedes interactuar con un código y ver los efectos inmediatamente en una serie de imágenes que puedes elegir. Para ello se ha utilizado el elemento HTML Canvas, que permite la generación de gráficos dinámicamente.

1.- Accede a la web:

2.- Elige el patrón o imagen que prefieras:

3.- Aparece a la izquierda la imagen elegida y a la derecha el código, que puedes modificar a tu gusto:

4.- Una vez realizadas las modificaciones deseadas, puedes exportar la imagen resultante:

Web del autor: http://elucidatedbinary.com/

miércoles, 5 de octubre de 2011

Multiplicación de matrices con JavaScript

Pues el título lo dice todo. Consiste en realizar un programa en JavaScript que multiplique dos matrices introducidas por el usuario. Para ello, en primer lugar, se piden las dimensiones de dichas matrices, se comprueba que son correctas [(m x n) * (n x p)] y si es así, se crean estas matrices, para que el usuario las rellene y posteriormente calcular su producto, que será otra matriz de dimensiones (m x p).

CÓDIGO HTML: pide las dimensiones de las matrices y ejecuta el código JavaScript

<html>
	<head>
		<script src="js/multiplicar_matrices4.js" language="javascript" type="text/javascript">
		</script>
	</head>
	<body>
		<div id="main" style="width:100%; height:350px">
			<div id="dimens" align="center" style="width:100%; background-color:FFA500">
				<div id="A" align="center" style="float:left; width:50%">
					<div>Dimensiones matriz A</div>
					<form name="dimA">
						Filas
						<input type="text" size="4" id="text">
						Columnas
						<input type="text" size="4" id="text">
					</form>
				</div>
				<div id="B" align="center" style="float:right; width:50%">
					<div>Dimensiones matriz B</div>
					<form name="dimB">
						Filas
						<input type="text" size="4" id="text">
						Columnas
						<input type="text" size="4" id="text">
					</form>
				</div>
				<input type="button" value="CREAR MATRICES" onclick="Comprobar ()" name="crear">
			</div>
	</body>
</html>

CÓDIGO JAVASCRIPT

var matriz1;
var matriz2;
var matrizRes;
var filaA;
var colA;
var filaB;
var colB;
var contador = 0;
//contador cuenta las veces que se accede, para que si no es la primera, se borren las capas creadas previamente.

//FUNCIONCES QUE DEBEMOS DEFINIR PARA CREAR LAS MATRICES
function CreaMatriz(n, m) {
	//DEFINIMOS EL TAMAÑO DE LA MATRIZ
	this.length = n;
	for (var i=0; i<n; i++) {
		this[i] = new Array(m);
	}
	return this;
}

function Multiplicar () {
	Inicializar ()
	for (i=0; i < filaA; i++){
		for (j=0; j < colB; j++){
			for (k=0; k < colA; k++){
				matrizRes[i][j] = matrizRes[i][j] + (matriz1[i][k] * matriz2[k][j]);
			}
		}
	}
}

function Mostrar () {
	Cargar ()
	
	var q = 0;
	
	for (i=0; i < matrizRes.length; i++){
		for (j=0; j < matrizRes.length; j++){
			document.matrizR.elements[q].value = matrizRes[i][j];
			matrizRes[i][j] = 0;
			q++;
		}
	}
}

//Esta función recoge los datos del formulario y los guarda en las matrices
function Cargar () {
	var q = 0;

	for (i=0; i<filaA; i++) {
		for (j=0; j<colA; j++) {
			matriz1[i][j] = parseInt(document.matrizA.elements[q].value);
			q++;
		}
	}
	
	q=0;
	for (i=0; i<filaB; i++) {
		for (j=0; j<colB; j++) {
			matriz2[i][j] = parseInt(document.matrizB.elements[q].value);
			q++;
		}
	}
	
	Multiplicar ()
}

//Comprueba que las dimensiones de las matrices son correctas para poder multiplicarlas
function Comprobar () {
	filaA = parseInt(document.dimA.elements[0].value);
	colA = parseInt(document.dimA.elements[1].value);
	filaB = parseInt(document.dimB.elements[0].value);
	colB = parseInt(document.dimB.elements[1].value);
		
	if (isNaN(filaA) || isNaN(colA) || isNaN(filaB) || isNaN(colB)) {
		alert("Valores no v\u00e1lidos.");
	}
	else if (colA != filaB) {
		alert("Dimensiones de las matrices no v\u00e1lidas.\nEl n\u00famero de columnas de A debe ser\nigual al n\u00famero de filas de B.");
	}
	else {
		if (contador > 0) {
			Borrar ()
		}
		matriz1 = new CreaMatriz(filaA, colA);
		matriz2 = new CreaMatriz(filaB, colB);
		CrearFormularios (filaA, colA, filaB, colB)
		matrizRes = new CreaMatriz(filaA, colB);
		CrearFormRes (filaA, colB)
		contador++
	}
}

function CrearFormularios (filA, colA, filB, colB) {
	var d = document.createElement("DIV");
	var fA = document.createElement("FORM");
	var fB = document.createElement("FORM");
	var A = document.createTextNode("Matriz A");
	var B = document.createTextNode("Matriz B");
	d.setAttribute("id", "matrices");
	d.setAttribute("align", "center");
	d.setAttribute("style", "width: 50%; height: 100%; float: left; background-color: 66FF66");
	fA.setAttribute("name", "matrizA");
	fB.setAttribute("name", "matrizB");
	
	var boton = document.createElement("INPUT");
	boton.setAttribute("type", "button");
	boton.setAttribute("value", "CALCULAR");
	boton.setAttribute("name", "button");
	boton.onclick=function(){Mostrar();}
	
	for (i=0; i<filA; i++) {
		var salto = document.createElement("BR");
		for (j=0; j<colA; j++) {
			var casilla = document.createElement("INPUT");
			casilla.setAttribute("type","text");
			casilla.setAttribute("size","4");
			casilla.setAttribute("name","text");
			fA.appendChild(casilla);
		}
		fA.appendChild(salto);
	}
	for (i=0; i<filB; i++) {
		var salto = document.createElement("BR");
		for (j=0; j<colB; j++) {
			var casilla = document.createElement("INPUT");
			casilla.setAttribute("type","text");
			casilla.setAttribute("size","4");
			casilla.setAttribute("name","text");
			fB.appendChild(casilla);
		}
		fB.appendChild(salto);
	}
	var salto = document.createElement("BR");
	d.appendChild(salto);
	d.appendChild(A);
	d.appendChild(fA);
	d.appendChild(B);
	d.appendChild(fB);
	var salto = document.createElement("BR");
	d.appendChild(salto);
	d.appendChild(boton);
	
	var otro = document.getElementById("main");
	otro.appendChild(d);
}

function CrearFormRes (filaA, colB) {
	var capa = document.createElement("DIV");
	var fRes = document.createElement("FORM");
	var res = document.createTextNode("Matriz Resultante");
	capa.setAttribute("id", "resultado");
	capa.setAttribute("align", "center");
	capa.setAttribute("style", "width: 50%; height: 100%; float:right; background-color: 20B2AA");
	fRes.setAttribute("name", "matrizR");
	
	for (i=0; i<filaA; i++) {
		var salto = document.createElement("BR");
		for (j=0; j<colB; j++) {
			var casilla = document.createElement("INPUT");
			casilla.setAttribute("type","text");
			casilla.setAttribute("size","4");
			casilla.setAttribute("name","text");
			casilla.readOnly ="true";
			fRes.appendChild(casilla);
		}
		fRes.appendChild(salto);
	}
	
	var salto = document.createElement("BR");
	capa.appendChild(salto);
	capa.appendChild(res);
	capa.appendChild(fRes);
	
	var otro = document.getElementById("main");
	otro.appendChild(capa);
}

function Inicializar () {
	for (i=0; i < matrizRes.length; i++){
		for (j=0; j < matrizRes.length; j++){
			matrizRes[i][j] = 0;
		}
	}
}

function Borrar () {
	var capa1 = document.getElementById("matrices");
	var capa2 = document.getElementById("resultado");
	var padre1 = capa1.parentNode;
	var padre2 = capa2.parentNode;
	padre1.removeChild(capa1);
	padre2.removeChild(capa2);
}

lunes, 19 de septiembre de 2011

Secuencia de imágenes con JavaScript

Dado el siguiente código en JavaScript, correspondiente a una secuencia de imágenes:

var SecuenciaID = null
var imagen = 0
var duracion = 1000
	
{imagenes = new CreaArray(4)
imagenes[1].src = "img/g1.jpg"
imagenes[2].src = "img/g2.png"
imagenes[3].src = "img/g3.jpg"
imagenes[4].src = "img/g4.jpg"
}
		
function CreaArray(n) {
	this.length = n
	for (var i = 1; i<=n; i++) {
		this[i] = new Image()
	}
	return this
}
		
function MostrarSecuencia() {
	{
		document.images["secuencia"].src = imagenes[imagen].src
		imagen++
		if ( imagen == 5 )
			imagen = 1
	}
	SecuenciaID = setTimeout("MostrarSecuencia()", duracion)
	SecuenciaEjecutandose = true
}
		
function IniciarSecuencia() {
	imagen = 1
	MostrarSecuencia()
}

Realizar los siguientes ejercicios:
  1. Conseguir que se muestre la secuencia de imágenes.
  2. Hacer que el tiempo durante el cual se muestra cada imagen sea distinto.
  3. Modificar el tamaño de cada imagen.
  4. Añadir música de fondo (debe estar sonando continuamente).
  5. Hacer que cuando termine la música de fondo, se pare la secuencia de imágenes.
  6. Añadir botones que inicien o paren la secuencia.
NOTA: en los cuatro primero ejercicios, el código JavaScript se añadió directamente dentro del código HTML, pero en los dos últimos, se creó un fichero por separado al que se referenciaba desde la cabecera del HTML.

EJERCICIO 1

<html>
	<script language="javascript" type="text/javascript">
		
		var SecuenciaID = null
		var imagen = 0
		var duracion = 1000
		
		{imagenes = new CreaArray(4)
		imagenes[1].src = "img/g1.jpg"
		imagenes[2].src = "img/g2.png"
		imagenes[3].src = "img/g3.jpg"
		imagenes[4].src = "img/g4.jpg"
		}
		
		function CreaArray(n) {
			this.length = n
			for (var i = 1; i<=n; i++) {
				this[i] = new Image()
			}
			return this
		}
		
		function MostrarSecuencia() {
			{
				document.images["secuencia"].src = imagenes[imagen].src
				imagen++
				if ( imagen == 5 )
					imagen = 1
			}
			SecuenciaID = setTimeout("MostrarSecuencia()", duracion)
			SecuenciaEjecutandose = true
		}
		
		function IniciarSecuencia() {
			imagen = 1
			MostrarSecuencia()
		}
		
	</script>
	
	<body onload="IniciarSecuencia()">
		<p><img src="img/g1.jpg" alt="Secuencia" name="secuencia"></p>
	</body>
</html>

EJERCICIO 2

<html>
	<script language="javascript" type="text/javascript">
		<!-- DECLARACIÓN DE VARIABLES -->
		var SecuenciaID = null
		var imagen = 0
		var tiempo = 1
		
		<!-- ARRAY DE IMÁGENES -->
		{imagenes = new CreaArray(4)
		imagenes[1].src = "img/g1.jpg"
		imagenes[2].src = "img/g2.png"
		imagenes[3].src = "img/g3.jpg"
		imagenes[4].src = "img/g4.jpg"
		}
		
		<!-- ARRAY DE "DURACIONES". Tiempo durante el cual se mostrará cada imagen -->
		{duracion = new CreaArray2(4)
		duracion[1] = 1000
		duracion[2] = 2000
		duracion[3] = 3000
		duracion[4] = 4000
		}
		
		<!-- FUNCIONCES QUE DEBEMOS DEFINIR PARA CREAR LOS ARRAYS -->
		function CreaArray(n) {
			<!-- DEFINIMOS EL TAMAÑO DEL ARRAY -->
			this.length = n
			for (var i = 1; i<=n; i++) {
				this[i] = new Image()
			}
			return this
		}
		
		function CreaArray2(n) {
			this.length = n
			for (var i = 1; i<=n; i++) {
				this[i] = 0
			}
			return this
		}
		
		function MostrarSecuencia() {
			{
				<!-- A TODAS LAS IMÁGENES DE <body> CUYO NOMBRE SEA "Secuencia" -->
				<!-- LE ASIGNAMOS LAS DEL ARRAY -->
				document.images["secuencia"].src = imagenes[imagen].src
				<!-- INCREMENTA EL VALOR DE "imagen" PARA QUE A CADA VUELTA MUESTRE LA -->
				<!-- SIGUIENTE SI LLEGA AL FINAL, COMIENZA POR LA PRIMERA DE NUEVO. -->
				imagen++
				if ( imagen == 5 )
					imagen = 1
			}
			<!-- setTimeout PERMITE EJECUTAR UNA FUNCIÓN PASADO CIERTO TIEMPO. -->
			SecuenciaID = setTimeout("MostrarSecuencia()", duracion[tiempo])
			tiempo++
			if ( tiempo == 5 )
				tiempo = 1
			SecuenciaEjecutandose = true
		}
		
		function IniciarSecuencia() {
			imagen = 1
			MostrarSecuencia()
		}
		
	</script>
	
	<body onload="IniciarSecuencia()">
		<p><img src="img/g1.jpg" alt="Secuencia" name="secuencia"></p>
	</body>
</html>

EJERCICIO 3

<html>
	<script language="javascript" type="text/javascript">
		<!-- DECLARACIÓN DE VARIABLES -->
		var SecuenciaID = null
		var imagen = 0
		var tiempo = 1
		
		<!-- ARRAY DE IMÁGENES -->
		{imagenes = new CreaArray(4)
		imagenes[1].src = "img/g1.jpg"
		imagenes[2].src = "img/g2.png"
		imagenes[3].src = "img/g3.jpg"
		imagenes[4].src = "img/g4.jpg"
		}
		
		<!-- ARRAY DE "DURACIONES". Tiempo durante el cual se mostrará cada imagen -->
		{duracion = new CreaArray2(4)
		duracion[1] = 1000
		duracion[2] = 2000
		duracion[3] = 3000
		duracion[4] = 4000
		}
		
		<!-- ARRAY DE "TAMAÑOS". Tamaño que irá tomando cada imagen -->
		{size = new CreaArray2(4)
		size[1] = 100
		size[2] = 200
		size[3] = 300
		size[4] = 400
		}
		
		<!-- FUNCIONCES QUE DEBEMOS DEFINIR PARA CREAR LOS ARRAYS -->
		function CreaArray(n) {
			<!-- DEFINIMOS EL TAMAÑO DEL ARRAY -->
			this.length = n
			for (var i = 1; i<=n; i++) {
				this[i] = new Image()
			}
			return this
		}
		
		function CreaArray2(n) {
			this.length = n
			for (var i = 1; i<=n; i++) {
				this[i] = 0
			}
			return this
		}
		
		function MostrarSecuencia () {
			{
				<!-- DEFINIR TAMAÑO DE LAS IMÁGENES -->
				document.images["secuencia"].width = size[imagen]
				document.images["secuencia"].height = size[imagen]
				
				<!-- A TODAS LAS IMÁGENES DE <body> CUYO NOMBRE SEA "Secuencia" -->
				<!-- LE ASIGNAMOS LAS DEL ARRAY -->
				document.images["secuencia"].src = imagenes[imagen].src
				<!-- INCREMENTA EL VALOR DE "imagen" PARA QUE A CADA VUELTA MUESTRE LA -->
				<!-- SIGUIENTE SI LLEGA AL FINAL, COMIENZA POR LA PRIMERA DE NUEVO. -->
				imagen++
				if ( imagen == 5 )
					imagen = 1
			}
			<!-- setTimeout PERMITE EJECUTAR UNA FUNCIÓN PASADO CIERTO TIEMPO. -->
			SecuenciaID = setTimeout("MostrarSecuencia()", duracion[tiempo])
			tiempo++
				if ( tiempo == 5 )
					tiempo = 1
			SecuenciaEjecutandose = true
		}
		
		function IniciarSecuencia() {
			imagen = 1
			MostrarSecuencia()
		}
		
	</script>
	
	<body onload="IniciarSecuencia()">
		<p><img src="img/g1.jpg" alt="Secuencia" name="secuencia"></p>
	</body>
</html>

EJERCICIO 4

<html>
	<script language="javascript" type="text/javascript">
		<!-- DECLARACIÓN DE VARIABLES -->
		var SecuenciaID = null
		var imagen = 0
		var tiempo = 1
		
		<!-- ARRAY DE IMÁGENES -->
		{imagenes = new CreaArray(4)
		imagenes[1].src = "img/g1.jpg"
		imagenes[2].src = "img/g2.png"
		imagenes[3].src = "img/g3.jpg"
		imagenes[4].src = "img/g4.jpg"
		}
		
		<!-- ARRAY DE "DURACIONES". Tiempo durante el cual se mostrará cada imagen -->
		{duracion = new CreaArray2(4)
		duracion[1] = 1000
		duracion[2] = 2000
		duracion[3] = 3000
		duracion[4] = 4000
		}
		
		<!-- ARRAY DE "TAMAÑOS". Tamaño que irá tomando cada imagen -->
		{size = new CreaArray2(4)
		size[1] = 100
		size[2] = 200
		size[3] = 300
		size[4] = 400
		}
		
		<!-- FUNCIONCES QUE DEBEMOS DEFINIR PARA CREAR LOS ARRAYS -->
		function CreaArray(n) {
			<!-- DEFINIMOS EL TAMAÑO DEL ARRAY -->
			this.length = n
			for (var i = 1; i<=n; i++) {
				this[i] = new Image()
			}
			return this
		}
		
		function CreaArray2(n) {
			this.length = n
			for (var i = 1; i<=n; i++) {
				this[i] = 0
			}
			return this
		}
		
		function MostrarSecuencia () {
			{
				<!-- DEFINIR TAMAÑO DE LAS IMÁGENES -->
				document.images["secuencia"].width = size[imagen]
				document.images["secuencia"].height = size[imagen]
				
				<!-- A TODAS LAS IMÁGENES DE <body> CUYO NOMBRE SEA "Secuencia" -->
				<!-- LE ASIGNAMOS LAS DEL ARRAY -->
				document.images["secuencia"].src = imagenes[imagen].src
				<!-- INCREMENTA EL VALOR DE "imagen" PARA QUE A CADA VUELTA MUESTRE LA -->
				<!-- SIGUIENTE SI LLEGA AL FINAL, COMIENZA POR LA PRIMERA DE NUEVO. -->
				imagen++
				if ( imagen == 5 )
					imagen = 1
			}
			<!-- setTimeout PERMITE EJECUTAR UNA FUNCIÓN PASADO CIERTO TIEMPO. -->
			SecuenciaID = setTimeout("MostrarSecuencia()", duracion[tiempo])
			tiempo++
				if ( tiempo == 5 )
					tiempo = 1
			SecuenciaEjecutandose = true
		}
		
		function IniciarSecuencia() {
			imagen = 1
			MostrarSecuencia()
		}
		
	</script>
	
	<body onload="IniciarSecuencia()">
		<div id="1">
			<p><img src="img/g1.jpg" alt="Secuencia" name="secuencia"></p>
		</div>
		<div id="2" style="position:absolute; top:300;">
			<EMBED src="sound/summer.mp3" autostart="true" loop="true">
		</div>
	</body>
</html>

EJERCICIO 5

Fichero .js
//DECLARACIÓN DE VARIABLES
var SecuenciaID = null
var imagen = 0
var tiempo = 1
var cancion = 0
		
//ARRAY DE IMÁGENES
{imagenes = new CreaArray(4)
imagenes[1].src = "img/g1.jpg"
imagenes[2].src = "img/g2.png"
imagenes[3].src = "img/g3.jpg"
imagenes[4].src = "img/g4.jpg"
}
		
//ARRAY DE "DURACIONES". Tiempo durante el cual se mostrará cada imagen
{duracion = new CreaArray2(4)
duracion[1] = 1000
duracion[2] = 2000
duracion[3] = 3000
duracion[4] = 4000
}
		
//ARRAY DE "TAMAÑOS". Tamaño que irá tomando cada imagen
{size = new CreaArray2(4)
size[1] = 100
size[2] = 200
size[3] = 300
size[4] = 400
}
		
//FUNCIONCES QUE DEBEMOS DEFINIR PARA CREAR LOS ARRAYS
function CreaArray(n) {
	//DEFINIMOS EL TAMAÑO DEL ARRAY
	this.length = n
	for (var i = 1; i<=n; i++) {
		this[i] = new Image()
	}
	return this
}
		
function CreaArray2(n) {
	this.length = n
	for (var i = 1; i<=n; i++) {
		this[i] = 0
	}
	return this
}
		
function MostrarSecuencia () {
	{
	//DEFINIR TAMAÑO DE LAS IMÁGENES
	document.images["secuencia"].width = size[imagen]
	document.images["secuencia"].height = size[imagen]
		
	//A TODAS LAS IMÁGENES DE <body> CUYO NOMBRE SEA "Secuencia"
	//LE ASIGNAMOS LAS DEL ARRAY
	document.images["secuencia"].src = imagenes[imagen].src
	//INCREMENTA EL VALOR DE "imagen" PARA QUE A CADA VUELTA MUESTRE LA
	//SIGUIENTE SI LLEGA AL FINAL, COMIENZA POR LA PRIMERA DE NUEVO.
	imagen ++
		if ( imagen == 5 )
			imagen = 1
	}
				
	cancion = cancion + duracion[tiempo]
			
	if ( cancion <= 60000 ) {
		//setTimeout PERMITE EJECUTAR UNA FUNCIÓN PASADO CIERTO TIEMPO.
		SecuenciaID = setTimeout("MostrarSecuencia()", duracion[tiempo])
			
		tiempo ++
			if ( tiempo == 5 )
				tiempo = 1
	}
}
		
function IniciarSecuencia() {
	imagen = 1
	MostrarSecuencia()
}

Fichero .html
<html>
	<head>
		<script src="js/secuencia.js" language="javascript" type="text/javascript">
		</script>
	</head>

	<body onload="IniciarSecuencia()">
		<p><img src="img/g1.jpg" alt="Secuencia" name="secuencia"></p>
		<EMBED src="sound/summer.mp3" autostart="true" loop="false" hidden="yes">

	</body>
</html>

EJERCICIO 6

Fichero .js
//DECLARACIÓN DE VARIABLES
var SecuenciaID = null
var SecuenciaEjecutandose = null
var imagen = 1
//Inicialmente imagen vale 1 y eliminamos la función IniciarSecuencia
var tiempo = 1
		
//ARRAY DE IMÁGENES
{imagenes = new CreaArray(4)
imagenes[1].src = "img/g1.jpg"
imagenes[2].src = "img/g2.png"
imagenes[3].src = "img/g3.jpg"
imagenes[4].src = "img/g4.jpg"
}
	
//ARRAY DE "DURACIONES". Tiempo durante el cual se mostrará cada imagen
{duracion = new CreaArray2(4)
duracion[1] = 1000
duracion[2] = 2000
duracion[3] = 3000
duracion[4] = 4000
}
		
//ARRAY DE "TAMAÑOS". Tamaño que irá tomando cada imagen
{size = new CreaArray2(4)
size[1] = 100
size[2] = 200
size[3] = 300
size[4] = 400
}
		
//FUNCIONCES QUE DEBEMOS DEFINIR PARA CREAR LOS ARRAYS
function CreaArray(n) {
	//DEFINIMOS EL TAMAÑO DEL ARRAY
	this.length = n
	for (var i = 1; i<=n; i++) {
		this[i] = new Image()
	}
	return this
}
		
function CreaArray2(n) {
	this.length = n
	for (var i = 1; i<=n; i++) {
		this[i] = 0
	}
	return this
}
		
function MostrarSecuencia () {
	if ( SecuenciaEjecutandose == true ) {
		//DEFINIR TAMAÑO DE LAS IMÁGENES
		document.images["secuencia"].width = size[imagen]
		document.images["secuencia"].height = size[imagen]
				
		//A TODAS LAS IMÁGENES DE <body> CUYO NOMBRE SEA "Secuencia"
		//LE ASIGNAMOS LAS DEL ARRAY
		document.images["secuencia"].src = imagenes[imagen].src
		//INCREMENTA EL VALOR DE "imagen" PARA QUE A CADA VUELTA MUESTRE LA
		//SIGUIENTE. SI LLEGA AL FINAL, COMIENZA POR LA PRIMERA DE NUEVO.
		imagen ++
		if ( imagen == 5 )
			imagen = 1
				
	//setTimeout PERMITE EJECUTAR UNA FUNCIÓN PASADO CIERTO TIEMPO.
	SecuenciaID = setTimeout("MostrarSecuencia()", duracion[tiempo])
		
	tiempo ++
	if ( tiempo == 5 )
		tiempo = 1
	}
			
}
		
function Iniciar () {
	SecuenciaEjecutandose = true
	MostrarSecuencia()
}
	
function Parar () {
	SecuenciaEjecutandose = false
	MostrarSecuencia()
}

Fichero .html
<html>
	<head>
		<script src="js/secuenciaConBotones.js" language="javascript" type="text/javascript">
		</script>
	</head>
	
	<body>
		<p><img src="img/g1.jpg" alt="Secuencia" name="secuencia"></p>
		<EMBED src="sound/summer.mp3" autostart="true" loop="true" hidden="yes">
		<input type="button" value="Iniciar secuencia" onClick="Iniciar()" style="position:absolute; left:500; top:50">
		<input type="button" value="Parar secuencia" onClick="Parar()" style="position:absolute; left:500; top:150">
	</body>
</html>

sábado, 17 de septiembre de 2011

Práctica HTML

Realizar una práctica libre de HTML utilizando distintas etiquetas y modificadores.
En mi caso cree una página con algunas de mis canciones favoritas, con imágenes, enlaces, etc. Además, en la parte superior de la página coloqué una tabla para practicar con las opciones que ofrece esta etiqueta.

<html>
	<head>
		<title>
			Mi m&#250sica favorita
		</title>
	</head>
	<body bgcolor="#E0F8F7" text="#04B4AE" link="#000000" vlink="#424242">
		<!--CABECERA-->
		<a name=top>
		<h1 align="center">MI M&#218SICA FAVORITA</h1>
		<hr color="#04B4AE" align="center" size="7" width="100%">
		
		<!--DESCRIPCIÓN DE MI PÁGINA WEB-->
		<div align="center">Esta p&#225gina contiene informaci&#243n sobre algunas de mis canciones favoritas.</div>
		
		<!--MENÚ-->
		<h3 align="center">CANCIONES:</h3>
		<table border="4" align="center" valign="middle" cellpadding="20">
			<tr>
				<td align="center" valign="middle">
					<a href="#cancion1">1.- BARROWLAND BALLROOM (Amy Macdonald)</a><br><br>
					<a href="#cancion2">2.- YELLOW (Coldplay)</a><br><br>
					<a href="#cancion3">3.- PARACHUTE (Cheryl Cole)</a>
				</td>
			</tr>
		</table>
		<br>
		<hr color="#04B4AE" align="center" size="5" width="100%">
		</a>
		
		<!--CANCIÓN 1-->
		<a name=cancion1>
		<h3><font color="#FF8000">1.- BARROWLAND BALLROOM</font></h3>
		<h4><font color="#FF8000"><u>Amy Macdonald</u></font></h4>
		<img src="http://pionerosonline.es/catalog/images/amy%20mcdonald%20this%20is%20ths%20life.jpg" alt="Car&#225tula This is the life" align="left" hspace="10">
		<pre><font color="#DF7401" size="+1" face="Arial"><b>Disco:</b> This is the life
<b>Letra:</b>
<p align="center"><i>Oh the lights outside they're as bright as the sun
They're much brighter than anyone.
Oh the girls in the queue, yes they're waiting for you...</i></p>
Si quieres ver la letra entera <a href="http://www.azlyrics.com/lyrics/amymacdonald/barrowlandballroom.html">HAZ CLIC AQU&#205</a>
<b>Videoclip:</b><a href="http://www.youtube.com/watch?v=K93FvHxzdlk"><img src="http://www.milbits.com/archivos/youtube-logo.jpg" alt="YouTube" align="middle" hspace="10" height="60"></a>
<p align="center"><i><blink><u>Nota:</u> La canci&#243n no tiene v&#237deo oficial.</blink></i></p>
<b>P&#225gina web oficial:</b> <a href="http://www.amymacdonald.co.uk/gb/home/">HAZ CLIC AQU&#205</a>
		</font>
		</pre>
		<div align="center"><a href="#top"><b>VOLVER AL INICIO</b></a></div>
		</a>
		<hr color="#000000" align="center" size="5" width="80%">
		
		<!--CANCIÓN 2-->
		<a name=cancion2>
		<h3 align="left"><font color="#D7DF01">2.- YELLOW</font></h3>
		<h4 align="left"><font color="#D7DF01"><u>Coldplay</u></font></h4>
		<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLsw-CHnE3MqezyBctmaZ6_XvKoBmUyEy19ubuc95-6g7njVbBMJelaF1zDZlfFG1MQMMattSHUJvLFrrsAdKxf_oEKVR4t3w6oY_xLzuCKzW7JEjDCL-tNuG2VxHbVP5y98styHi-NfKS/s400/coldplay-parachutes.jpg" alt="Car&#225tula Parachutes" align="right" hspace="10" height="350">
		<pre><font color="#868A08" size="+1" face="Arial"><b>Disco:</b> Parachutes
<b>Letra:</b>
<p align="center"><i>Look at the stars,
Look how they shine for you,
And everything you do...</i></p>
Si quieres ver la letra entera <a href="http://www.azlyrics.com/lyrics/coldplay/yellow.html">HAZ CLIC AQU&#205</a>
<b>Videoclip:</b><a href="http://www.youtube.com/watch?v=1MwjX4dG72s"><img src="http://www.milbits.com/archivos/youtube-logo.jpg" alt="YouTube" align="middle" hspace="10" height="60"></a>
<p align="center"><i><blink><u>Nota:</u> V&#237deo oficial.</blink></i></p>
<b>P&#225gina web oficial:</b> <a href="http://www.coldplay.com/">HAZ CLIC AQU&#205</a>
		</font>
		</pre>
		<div align="center"><a href="#top"><b>VOLVER AL INICIO</b></a></div>
		</a>
		<hr color="#000000" align="center" size="5" width="80%">
		
		<!--CANCIÓN 3-->
		<a name=cancion3>
		<h3><font color="#01DF01">3.- PARACHUTE</font></h3>
		<h4><font color="#01DF01"><u>Cheryl Cole</u></font></h4>
		<img src="http://strictly-cheryl.tk/wp-content/uploads/2011/01/Cheryl-Cole-3-Words-album-cover.jpg" alt="Car&#225tula 3 Words" align="left" hspace="10" height="350">
		<pre><font color="#088A08" size="+1" face="Arial"><b>Disco:</b> 3 Words
<b>Letra:</b>
<p align="center"><i>I don't tell anyone about the way you hold my hand
I don't tell anyone about the things that we have planned
Won't tell anybody, won't tell anybody...</i></p>
Si quieres ver la letra entera <a href="http://www.azlyrics.com/lyrics/cherylcole/parachute.html">HAZ CLIC AQU&#205</a>
<b>Videoclip:</b><a href="http://www.youtube.com/watch?v=-AWoZmAxKxg"><img src="http://www.milbits.com/archivos/youtube-logo.jpg" alt="YouTube" align="middle" hspace="10" height="60"></a>
<p align="center"><i><blink><u>Nota:</u> V&#237deo oficial.</blink></i></p>
<b>P&#225gina web oficial:</b> <a href="http://www.cherylcole.com/">HAZ CLIC AQU&#205</a>
		</font>
		</pre>
		<div align="center"><a href="#top"><b>VOLVER AL INICIO</b></a></div>
		</a>
		<hr color="#000000" align="center" size="5" width="80%">
		
	</body>
</html>

lunes, 12 de septiembre de 2011

Imágenes, textos y capas en HTML

Para empezar a conocer HTML, realizamos varias prácticas que consistían en utilizar las distintas etiquetas, añadiendo sus modificadores, etc. Muchas de estás prácticas eran progresivas, es decir, sobre la misma práctica se iban modificando cosas hasta tener el resultado final.

La primera práctica consiste en colocar varias imágenes y modificar su estilo.

<html>
	<head>
		<title>PR&#193CTICA 1</title>
	</head>
	<body>
		<h2 align="center">Pr&#225ctica 1</h2>
		<hr align="center" size="10" width="80%" color="blue">
		<img src="chrome.jpg" alt="Tama&#241o original" border="3">
		<img src="firefox.png" alt="Achatada" border="0" height="300" width="600">
		<img src="explorer.jpg" alt="Alargada" border="0" height="600" width="300">
		<img src="opera.png" alt="Doble grande" border="0" height="600">
	</body>
</html>

1ª MODIFICACIÓN
Es buena práctica almacenar las imágenes, sonidos, vídeo, etc. en un directorio aparte, para que las rutas sean más claras y lo tengamos todo organizado.
Esta modificación consiste en crear un directorio para las imágenes, guardar éstas en él y modificar lo que sea necesario para que se siga viendo correctamente.

<html>
	<head>
		<title>PR&#193CTICA 1.1: IM&#193GENES EN DIRECTORIOS</title>
	</head>
	<body>
		<h2 align="center">Pr&#225ctica 1.1</h2>
		<hr align="center" size="10" width="80%" color="blue">
		<img src="img/chrome.jpg" alt="Tama&#241o original" border="3">
		<img src="img/firefox.png" alt="Achatada" border="0" height="300" width="600">
		<img src="img/explorer.jpg" alt="Alargada" border="0" height="600" width="300">
		<img src="img/opera.png" alt="Doble grande" border="0" height="600">
	</body>
</html>

2ª MODIFICACIÓN
Añadir texto con distintos modificadores (color, cursiva, negrita, etc.). Además, poner enlaces en las imágenes para que dirijan a la web que queramos.

<html>
	<head>
		<title>PR&#193CTICA 1.2: CON TEXTOS</title>
	</head>
	<body>
		<h2 align="center">Pr&#225ctica 1.2</h2>
		<hr align="center" size="10" width="80%" color="blue"> 
		<marquee><s>Texto en marquesina y tachado.</s></marquee>
		<!-- Al ponerlo en marquesina, se pone directamente encima de la imagen -->
		<a href="http://www.google.com/chrome?hl=es"><img src="img/chrome.jpg" alt="Tama&#241o original" border="3"></a>
		<b><i>Texto en negrita y cursiva.</i></b>
		<a href="http://www.mozilla-europe.org/es/"><img src="img/firefox.png" alt="Achatada" border="0" height="300" width="600" align="top"></a>
		<blink><font color="blue">Texto parpadeante y azul.</font></blink>
		<a href="http://windows.microsoft.com/es-ES/windows/downloads?T1=downloadsIE"><img src="img/explorer.jpg" alt="Alargada" border="0" height="600" width="300" align="middle"></a>
		Texto sin marcadores.
		<a href="http://www.opera.com/browser/download/"><img src="img/opera.png" alt="Doble grande" border="0" height="600" align="bottom"></a>
	</body>
</html>

3ª MODIFICACIÓN
Crear distintas capas que contengan las distintas partes de la página que hemos estado haciendo.

<html>
	<head>
		<title>PR&#193CTICA 1.3: CON CAPAS</title>
	</head>
	<body>
		<div name="capa_inicio">
		<h2 align="center">Pr&#225ctica 1.3</h2>
		<hr align="center" size="10" width="80%" color="blue"> 
		</div>
		
		<div name="capa_imagen1">
		<marquee><s>Texto en marquesina y tachado.</s></marquee>
		<a href="http://www.google.com/chrome?hl=es"><img src="img/chrome.jpg" alt="Tama&#241o original" border="3"></a>
		</div>
		
		<div name="capa_imagen2">
		<b><i>Texto en negrita y cursiva.</i></b>
		<a href="http://www.mozilla-europe.org/es/"><img src="img/firefox.png" alt="Achatada" border="0" height="300" width="600" align="top"></a>
		</div>
		
		<div name="capa_imagen3">
		<blink><font color="blue">Texto parpadeante y azul.</font></blink>
		<a href="http://windows.microsoft.com/es-ES/windows/downloads?T1=downloadsIE"><img src="img/explorer.jpg" alt="Alargada" border="0" height="600" width="300" align="middle"></a>
		</div>
		
		<div name="capa_imagen4">
		Texto sin marcadores.
		<a href="http://www.opera.com/browser/download/"><img src="img/opera.png" alt="Doble grande" border="0" height="600" align="bottom"></a>
		</div>
	</body>
</html>

4ª MODIFICACIÓN
Añadir estilos a las capas.

<html>
	<head>
		<title>PR&#193CTICA 1.4: CON CAPAS (OPCIONAL)</title>
	</head>
	<body>
		<div name="capa_inicio" style="position:absolute; left:100; top:100;
		visibility:hidden; background-color:#66CCFF">
		<h2 align="center">Pr&#225ctica 1.4</h2>
		<hr align="center" size="10" width="80%" color="blue"> 
		</div>
		
		<div name="capa_imagen1" style="position:absolute; left:20; top:20; width:200px;
		height:200px; overflow:scroll">
		<marquee><s>Texto en marquesina y tachado.</s></marquee>
		<a href="http://www.google.com/chrome?hl=es"><img src="img/chrome.jpg" alt="Tama&#241o original" border="3"></a>
		</div>
		
		<div name="capa_imagen2" style="position:absolute; left:300; top:20; width:400px;
		height:200px; background-color:#FF6600; overflow:hidden">
		<b><i>Texto en negrita y cursiva.</i></b>
		<a href="http://www.mozilla-europe.org/es/"><img src="img/firefox.png" alt="Achatada" border="0" height="300" width="600" align="top"></a>
		</div>
		
		<div name="capa_imagen3" style="position:absolute; left:400; top:280; width:300px;
		height:600px; overflow:auto">
		<blink><font color="blue">Texto parpadeante y azul.</font></blink>
		<a href="http://windows.microsoft.com/es-ES/windows/downloads?T1=downloadsIE"><img src="img/explorer.jpg" alt="Alargada" border="0" height="600" width="300" align="middle"></a>
		</div>
		
		<div name="capa_imagen4" style="position:absolute; left:10; top:900; width:900px;
		height:700px; background-image:url(http://hd-wallpaper.org/wallpapers/10/Color_Flow_Light_Effect.jpg)">
		Texto sin marcadores.
		<a href="http://www.opera.com/browser/download/"><img src="img/opera.png" alt="Doble grande" border="0" height="600" align="bottom"></a>
		</div>
	</body>
</html>

La etiqueta del salto de línea <br> no me la coge dentro del código, así que la he eliminado. Simplemente la utilizaba para separar un poco unas imágenes de otras.