<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"> <channel><title>Linea de Codigo</title> <link>http://lineadecodigo.com</link> <description>/* Programación en la red */</description> <lastBuildDate>Wed, 22 Feb 2012 07:00:37 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/LineaDeCodigo" /><feedburner:info uri="lineadecodigo" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Evitar que un programa Java se cargue dos veces</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/YXMFEnizPTI/</link> <comments>http://lineadecodigo.com/java/evitar-que-un-programa-java-se-cargue-dos-veces/#comments</comments> <pubDate>Wed, 22 Feb 2012 07:00:37 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[escuchador]]></category> <category><![CDATA[Java Web Start]]></category> <category><![CDATA[puerto]]></category> <category><![CDATA[ServerSocket]]></category> <category><![CDATA[SingleInstanceService]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3883</guid> <description><![CDATA[Algunos de vosotros nos habéis preguntado sobre cómo controlar que un programa Java se cargue dos veces. Es decir, que si ya lo hemos lanzado, evitemos que se vuelva a lanzar. Existen formas desde Java Web Start y el modo SingleInstanceService para evitar que un programa se cargue dos veces. Pero en nuestro caso vamos [...]]]></description> <content:encoded><![CDATA[<p>Algunos de vosotros nos habéis preguntado sobre cómo controlar que un programa <a
href="http://www.manualweb.net/tutorial-java/" title="Tutorial de Java">Java</a> se cargue dos veces. Es decir, que si ya lo hemos lanzado, evitemos que se vuelva a lanzar.</p><p>Existen formas desde Java Web Start y el modo SingleInstanceService para evitar que un programa se cargue dos veces. Pero en nuestro caso vamos a realizarlo de una forma "más manual" en <a
href="http://www.manualweb.net/tutorial-java/" title="Tutorial de Java">Java</a>, pero muy efectiva.</p><p>El truco es que el programa <a
href="http://www.manualweb.net/tutorial-java/" title="Tutorial de Java">Java</a> cree un objeto que esté escuchando a un puerto específico del ordenador. Para ello utilizamos un <a
href="http://www.w3api.com/wiki/Java:ServerSocket" title="Clase Java ServerSocket">ServerSocket</a>, objeto que nos permite crear un objeto escuchando a un determinado puerto.</p><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://w3api.com/wiki/Java:ServerSocket"><span style="color: #aaaadd; font-weight: bold;">ServerSocket</span></a> SERVER_SOCKET<span style="color: #66cc66;">;</span>
SERVER_SOCKET = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://w3api.com/wiki/Java:ServerSocket"><span style="color: #aaaadd; font-weight: bold;">ServerSocket</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1334</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre><blockquote><p>Escoge un puerto que no sea el estándar de los protocolos: 80 para el http, 21 para el ftp,... Vamos elige un número de puerto "raro".</p></blockquote><p>Además vemos que el objeto <a
href="http://www.w3api.com/wiki/Java:ServerSocket" title="Clase Java ServerSocket">ServerSocket</a> que hemos instanciado es un objeto estático dentro de nuestro programa. Así, nuestro programa tendrá un listener sobre un puerto, al que nadie dirá nada, pero que lo dejará como reservado.</p><p>Lo que sucede es que si intentamos volver a crear un escuchador sobre ese puerto, saldrá una excepción indicando que el puerto ya está en uso. Esto nos permite controlar que ya hay una instancia de nuestro programa ejecutándose.</p><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
  SERVER_SOCKET = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://w3api.com/wiki/Java:ServerSocket"><span style="color: #aaaadd; font-weight: bold;">ServerSocket</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1334</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
  <a href="http://w3api.com/wiki/Java:System"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Es la primera instancia de la aplicación...&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
  <a href="http://w3api.com/wiki/Java:System"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Pulsa OK para terminar&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
  <a href="http://w3api.com/wiki/Java:System"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">in</span>.<span style="color: #006600;">read</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://w3api.com/wiki/Java:IOException"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a> x<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <a href="http://w3api.com/wiki/Java:System"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Otra instancia de la aplicación se está ejecutando...&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre><p>Con este simple código podemos evitar que un programa <a
href="http://www.manualweb.net/tutorial-java/" title="Tutorial de Java">Java</a> se ejecute dos veces.<strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/java/cerrar-un-frame-en-awt/" rel="bookmark" title="Diciembre 16, 2007">Cerrar un frame en AWT</a></li><li><a
href="http://lineadecodigo.com/java/pasar-parametros-a-una-aplicacion-java/" rel="bookmark" title="Marzo 1, 2011">Pasar parámetros a una aplicación Java</a></li><li><a
href="http://lineadecodigo.com/java/finalizar-un-objeto-en-java/" rel="bookmark" title="Marzo 4, 2011">Finalizar un objeto en Java</a></li><li><a
href="http://lineadecodigo.com/java/conocer-el-directorio-de-trabajo-de-java/" rel="bookmark" title="Septiembre 14, 2011">Conocer el directorio de trabajo de Java</a></li><li><a
href="http://lineadecodigo.com/asp/leer-un-fichero-de-texto-en-asp/" rel="bookmark" title="Septiembre 29, 2009">Leer un fichero de texto en ASP</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/8crE_-Dn_NAsya06SkDqyuQr_e4/0/da"><img src="http://feedads.g.doubleclick.net/~a/8crE_-Dn_NAsya06SkDqyuQr_e4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/8crE_-Dn_NAsya06SkDqyuQr_e4/1/da"><img src="http://feedads.g.doubleclick.net/~a/8crE_-Dn_NAsya06SkDqyuQr_e4/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=YXMFEnizPTI:V8tiz5L3KMI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=YXMFEnizPTI:V8tiz5L3KMI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=YXMFEnizPTI:V8tiz5L3KMI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=YXMFEnizPTI:V8tiz5L3KMI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=YXMFEnizPTI:V8tiz5L3KMI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=YXMFEnizPTI:V8tiz5L3KMI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=YXMFEnizPTI:V8tiz5L3KMI:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/YXMFEnizPTI" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/java/evitar-que-un-programa-java-se-cargue-dos-veces/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://lineadecodigo.com/java/evitar-que-un-programa-java-se-cargue-dos-veces/</feedburner:origLink></item> <item><title>Guardar unos Properties con Java</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/qs-iYimQG08/</link> <comments>http://lineadecodigo.com/java/guardar-unos-properties-con-java/#comments</comments> <pubDate>Tue, 21 Feb 2012 22:56:03 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[FileOutputStream]]></category> <category><![CDATA[IOException]]></category> <category><![CDATA[properties]]></category> <category><![CDATA[store]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3876</guid> <description><![CDATA[Hemos visto varios ejemplos sobre cómo leer el contenido de unos Properties o cómo modificar el contenido de unos Properties. Pero, qué tenemos que hacer si una vez modificados queremos guardarlos en el fichero. Ya que la modificación solo se aplica al tiempo de vida de la ejecución del programa Java. Veamos ahora como podemos [...]]]></description> <content:encoded><![CDATA[<p>Hemos visto varios ejemplos sobre cómo leer el contenido de unos <a
href="http://www.w3api.com/wiki/Java:Properties" title="Clase Properties de Java">Properties</a> o cómo modificar el contenido de unos <a
href="http://www.w3api.com/wiki/Java:Properties" title="Clase Properties de Java">Properties</a>. Pero, qué tenemos que hacer si una vez modificados queremos guardarlos en el fichero. Ya que la modificación solo se aplica al tiempo de vida de la ejecución del programa <a
href="http://www.manualweb.net/tutorial-java/" title="Tutorial de Java">Java</a>.</p><p>Veamos ahora como podemos guardar unos Properties con Java. Lo primero será definir unos <a
href="http://www.w3api.com/wiki/Java:Properties" title="Clase Properties de Java">Properties</a> mediante la clase <a
href="http://www.w3api.com/wiki/Java:Properties" title="Clase Properties de Java">Properties</a>. Los vamos a generar vía código, aunque podíamos haberlos leído de un fichero.</p><pre class="java" style="font-family:monospace;"><a href="http://w3api.com/wiki/Java:Properties"><span style="color: #aaaadd; font-weight: bold;">Properties</span></a> prop = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://w3api.com/wiki/Java:Properties"><span style="color: #aaaadd; font-weight: bold;">Properties</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
prop.<span style="color: #006600;">setProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;nombre&quot;</span>,<span style="color: #ff0000;">&quot;Linea de Código&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
prop.<span style="color: #006600;">setProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;url&quot;</span>,<span style="color: #ff0000;">&quot;http://lineadecodigo.com&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre><p>El siguiente paso será definir el fichero el cual queremos guardar los <a
href="http://www.w3api.com/wiki/Java:Properties" title="Clase Properties de Java">Properties</a>. Y como todo manejo de ficheros deberemos de abrirle un <a
href="http://www.w3api.com/wiki/Java:FileOutputStream" title="Clase FileOutputStream">FileOutputStream</a>.</p><pre class="java" style="font-family:monospace;"><a href="http://w3api.com/wiki/Java:FileOutputStream"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a> os = <a href="http://w3api.com/wiki/Java:FileOutputStream"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;fichero.prop&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre><p>Ahora va lo más importante, y es que dentro de <a
href="http://www.w3api.com/wiki/Java:Properties" title="Clase Properties de Java">Properties</a> tenemos el método <a
href="http://www.w3api.com/wiki/Java:Properties.store()" title="Método store de la clase Properties">.store()</a> el cual persistirá los datos sobre un <a
href="http://www.w3api.com/wiki/Java:FileOutputStream" title="Clase FileOutputStream">FileOutputStream</a> que le pasemos como parámetro. Curiosamente el que acabamos de crear.</p><pre class="java" style="font-family:monospace;">prop.<span style="color: #006600;">store</span><span style="color: #66cc66;">&#40;</span>os, <span style="color: #ff0000;">&quot;Fichero de Propiedades de la Web&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre><p>Una de las cosas que tienes que tener en cuenta es que en los manejos de stream puede saltar siempre la <a
href="http://www.w3api.com/wiki/Java:IOException" title="Excepción Java IOException">IOException.</a> Así que nos crearemos nuestro bloque try-catch.</p><pre class="java" style="font-family:monospace;"><a href="http://w3api.com/wiki/Java:FileOutputStream"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a> os = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
  os=<span style="color: #000000; font-weight: bold;">new</span> <a href="http://w3api.com/wiki/Java:FileOutputStream"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;fichero.prop&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
  prop.<span style="color: #006600;">store</span><span style="color: #66cc66;">&#40;</span>os, <span style="color: #ff0000;">&quot;Fichero de Propiedades de la Web&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #66cc66;">&#40;</span><a href="http://w3api.com/wiki/Java:IOException"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a> ioe<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>ioe.<span style="color: #006600;">printStackTrace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><span style="color: #66cc66;">&#125;</span></pre><p><strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/java/modificar-valores-de-un-fichero-properties/" rel="bookmark" title="Diciembre 23, 2007">Modificar valores de un fichero Properties</a></li><li><a
href="http://lineadecodigo.com/java/leer-valores-de-fichero-de-properties/" rel="bookmark" title="Enero 24, 2007">Leer valores de fichero de properties</a></li><li><a
href="http://lineadecodigo.com/java/escribir-un-fichero-iso-latin-1/" rel="bookmark" title="Septiembre 25, 2011">Escribir un fichero ISO Latin 1</a></li><li><a
href="http://lineadecodigo.com/java/numero-de-lineas-de-un-fichero/" rel="bookmark" title="Noviembre 20, 2006">Número de líneas de un fichero</a></li><li><a
href="http://lineadecodigo.com/java/escribir-un-fichero-utf-8/" rel="bookmark" title="Octubre 12, 2011">Escribir un fichero UTF-8</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/D8Aj5lBef9Y9vfLg-ggjHDGQmb8/0/da"><img src="http://feedads.g.doubleclick.net/~a/D8Aj5lBef9Y9vfLg-ggjHDGQmb8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/D8Aj5lBef9Y9vfLg-ggjHDGQmb8/1/da"><img src="http://feedads.g.doubleclick.net/~a/D8Aj5lBef9Y9vfLg-ggjHDGQmb8/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=qs-iYimQG08:4vn9Rtahzxo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=qs-iYimQG08:4vn9Rtahzxo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=qs-iYimQG08:4vn9Rtahzxo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=qs-iYimQG08:4vn9Rtahzxo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=qs-iYimQG08:4vn9Rtahzxo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=qs-iYimQG08:4vn9Rtahzxo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=qs-iYimQG08:4vn9Rtahzxo:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/qs-iYimQG08" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/java/guardar-unos-properties-con-java/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://lineadecodigo.com/java/guardar-unos-properties-con-java/</feedburner:origLink></item> <item><title>Crear un slider con jQuery</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/30X7bjy9-I8/</link> <comments>http://lineadecodigo.com/jquery/crear-un-slider-con-jquery/#comments</comments> <pubDate>Sun, 19 Feb 2012 07:00:04 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[modernizr]]></category> <category><![CDATA[Modernizr.load]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[polyfill]]></category> <category><![CDATA[slider]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3865</guid> <description><![CDATA[Ahora que hemos publicado un artículo sobre cómo montar un slider en HTML5 muchas de las preguntas que nos están llegando son relativas al no soporte del slider HTML5 en ciertos navegadores y consultas sobre cómo montar una alternativa. Lo que vamos a ver en este artículo es como crear un slider con jQuery. Y [...]]]></description> <content:encoded><![CDATA[<p>Ahora que hemos publicado un <a
href="http://lineadecodigo.com/html5/elemento-rango-en-formularios-html5/" title="Crear un slider en HTML5">artículo sobre cómo montar un slider en HTML5</a> muchas de las preguntas que nos están llegando son relativas al no soporte del slider <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a> en ciertos navegadores y consultas sobre cómo montar una alternativa.</p><p>Lo que vamos a ver en este artículo es como crear un slider con <a
href="http://www.manualweb.net/tutorial-jquery/" title="Tutorial de jQuery">jQuery</a>. Y no es que <a
href="http://www.manualweb.net/tutorial-jquery/" title="Tutorial de jQuery">jQuery</a> nos de un slider como elemento base de su lenguaje, si no que vamos a utilizar un <a
href="https://github.com/freqdec/fd-slider" title="Plugin jd-slider de jQuery">plugin de jQuery para poder crear un slider</a>.</p><p>En concreto utilizamos <a
href="https://github.com/freqdec/fd-slider" title="Plugin fd-slider de jQuery">el plugin fd-slider</a>. Además vamos a utilizar <a
href="http://lineadecodigo.com/javascript/como-utilizar-un-polyfill-con-modernizr/" title="Utilizar un polyfill con Modernizr">la técnica de polyfills que vimos el otro día con el ejemplo sobre un placeholder</a>.</p><p>Lo bueno del <a
href="https://github.com/freqdec/fd-slider" title="Plugin fd-slider de jQuery">plugin fd-slider</a> es que al ser un polyfill nos permite construir nuestra página con <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a> y solo se ejecutará en aquellos navegadores que lo necesiten y durante el tiempo que lo necesiten.</p><p>Lo primero que tenemos que saber del plugin es que lo componen dos ficheros:</p><pre>fd-slider.js
fd-slider.css</pre><p>Utilizando el loader de <a
href="http://www.manualweb.net/tutorial-modernizr/" title="Manual de Modernizr">Modernizr</a> veremos que quedaría de la siguiente forma:</p><pre class="javascript" style="font-family:monospace;">Modernizr.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	test<span style="color: #339933;">:</span>Modernizr.<span style="color: #660066;">inputtypes</span>.<span style="color: #660066;">range</span><span style="color: #339933;">,</span>
	nope<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'fd-slider.js'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'fd-slider.css'</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Vemos que la capacidad que validamos del <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a> es Modernizr.inputtypes.range.</p><p>Una vez cargados los ficheros del <a
href="https://github.com/freqdec/fd-slider" title="Plugin fd-slider de jQuery">plugin fd-slider</a> tenemos que lanzar el siguiente código para inicializar el plugin:</p><pre class="javascript" style="font-family:monospace;">fdSlider.<span style="color: #660066;">onDomReady</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Así que insertaremos dicho código dentro del polyfill.</p><pre class="javascript" style="font-family:monospace;">Modernizr.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  test<span style="color: #339933;">:</span>Modernizr.<span style="color: #660066;">inputtypes</span>.<span style="color: #660066;">range</span><span style="color: #339933;">,</span>
  nope<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'fd-slider.js'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'fd-slider.css'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  complete<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fdSlider<span style="color: #009900;">&#41;</span>fdSlider.<span style="color: #660066;">onDomReady</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Ya tendremos cargado nuestro slider con <a
href="http://www.manualweb.net/tutorial-jquery/" title="Tutorial de jQuery">jQuery</a>funcionando en la página.</p><p>Os podéis descargar el <a
href="https://github.com/freqdec/fd-slider" title="Plugin fd-slider de jQuery">plugin fd-slider</a> desde <a
href="https://github.com/freqdec/fd-slider" title="Plugin fd-slider de jQuery">https://github.com/freqdec/fd-slider</a><strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/javascript/como-utilizar-un-polyfill-con-modernizr/" rel="bookmark" title="Febrero 17, 2012">Como utilizar un Polyfill con Modernizr</a></li><li><a
href="http://lineadecodigo.com/jquery/utilizar-placeholder-con-jquery/" rel="bookmark" title="Febrero 16, 2012">Utilizar Placeholder con jQuery</a></li><li><a
href="http://lineadecodigo.com/html5/controlar-volumen-de-video-html5-con-un-slider/" rel="bookmark" title="Febrero 3, 2012">Controlar volumen de vídeo HTML5 con un Slider</a></li><li><a
href="http://lineadecodigo.com/html5/datalist-en-html5/" rel="bookmark" title="Febrero 1, 2012">DataList en HTML5</a></li><li><a
href="http://lineadecodigo.com/javascript/modernizr-y-las-capacidades-html5-y-css3/" rel="bookmark" title="Enero 3, 2012">Modernizr y las capacidades HTML5 y CSS3</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/CwTOp0GnVZmljoTYtOABrcS1MZo/0/da"><img src="http://feedads.g.doubleclick.net/~a/CwTOp0GnVZmljoTYtOABrcS1MZo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/CwTOp0GnVZmljoTYtOABrcS1MZo/1/da"><img src="http://feedads.g.doubleclick.net/~a/CwTOp0GnVZmljoTYtOABrcS1MZo/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=30X7bjy9-I8:LKfJO4d8eh8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=30X7bjy9-I8:LKfJO4d8eh8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=30X7bjy9-I8:LKfJO4d8eh8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=30X7bjy9-I8:LKfJO4d8eh8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=30X7bjy9-I8:LKfJO4d8eh8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=30X7bjy9-I8:LKfJO4d8eh8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=30X7bjy9-I8:LKfJO4d8eh8:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/30X7bjy9-I8" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/jquery/crear-un-slider-con-jquery/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://lineadecodigo.com/jquery/crear-un-slider-con-jquery/</feedburner:origLink></item> <item><title>Como utilizar un Polyfill con Modernizr</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/gjp-oIVk4SI/</link> <comments>http://lineadecodigo.com/javascript/como-utilizar-un-polyfill-con-modernizr/#comments</comments> <pubDate>Fri, 17 Feb 2012 21:00:30 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[complete]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[modernizr]]></category> <category><![CDATA[Modernizr.input.placeholder]]></category> <category><![CDATA[nope]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[polyfill]]></category> <category><![CDATA[yep]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3857</guid> <description><![CDATA[Modernizr como librería Javascript está orientada a poder conocer el soporte de las capacidades CSS3 y HTML5 cuando nos ejecutemos en un determinado navegador. Pero la potencia de Modernizr no se queda solo ahí, si no que podemos hacer otras cosas como utilizar un polyfill. Pero, ¿qué es un polyfill? Pues un polyfill es como [...]]]></description> <content:encoded><![CDATA[<p><a
href="http://www.manualweb.net/tutorial-modernizr/" title="Manual de Modernizr">Modernizr</a> como librería <a
href="http://www.manualweb.net/tutorial-javascript/" title="Tutorial de Javascript">Javascript</a> está orientada a poder conocer el soporte de las capacidades <a
href="http://www.manualweb.net/tutorial-css/" title="Manual de CSS">CSS3</a> y <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a> cuando nos ejecutemos en un determinado navegador. Pero la potencia de Modernizr no se queda solo ahí, si no que podemos hacer otras cosas como utilizar un polyfill.</p><p>Pero, ¿qué es un polyfill? Pues un polyfill es como se denomina a una librería <a
href="http://www.manualweb.net/tutorial-javascript/" title="Tutorial de Javascript">Javascript</a> que nos permite cubrir las capacidades <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a>/<a
href="http://www.manualweb.net/tutorial-css/" title="Manual de CSS">CSS3</a> que los navegadores no soportan. Es decir, completan al navegador para que se pueda ejecutar una página web construida con <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a>/<a
href="http://www.manualweb.net/tutorial-css/" title="Manual de CSS">CSS3</a> sin problemas.</p><p>Es decir, el código que creemos será estándar <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a>/<a
href="http://www.manualweb.net/tutorial-css/" title="Manual de CSS">CSS3</a> de tal manera que <a
href="http://www.manualweb.net/tutorial-modernizr/" title="Manual de Modernizr">Modernizr</a> nos ayudará a utilizar solo el polyfill si se necesita debido a las carencias del navegador.</p><p>Lo bueno es que <a
href="https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills" title="Librería de Polyfills de Modernizr">Modernizr ya cuenta con una extensa librería de Polyfills</a>.</p><p>En nuestro ejemplo, que nos explique como utilizar un Polyfill en <a
href="http://www.manualweb.net/tutorial-modernizr/" title="Manual de Modernizr">Modernizr</a>, vamos a <a
href="http://lineadecodigo.com/html5/placeholder-marcadores-de-posicion-en-html5/" title="Crear un Placeholder con HTML5">crear una página que tenga un Placeholder</a> y en el caso que no haya soporte del placeholder utilizaremos un <a
href="http://lineadecodigo.com/jquery/utilizar-placeholder-con-jquery/" title="Plugin de jQuery que simule un Placeholder">plugin de jQuery que nos simule en Placeholder</a>. Ambos artículos ya explicados en <a
href="http://lineadecodigo.com" title="Línea de Código">Línea de Código</a>.</p><p>Para utilizar el polyfill de <a
href="http://www.manualweb.net/tutorial-modernizr/" title="Manual de Modernizr">Modernizr</a> tenemos que conocer el método Modernizr.load. La filosofía de este método es la siguiente:</p><pre class="javascript" style="font-family:monospace;">Modernizr.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  test<span style="color: #339933;">:</span> capacidad<span style="color: #339933;">-</span>a<span style="color: #339933;">-</span>validar<span style="color: #339933;">,</span>
  yep <span style="color: #339933;">:</span> <span style="color: #3366CC;">'fichero-a-cargar-si-correcto.js'</span><span style="color: #339933;">,</span>
  nope<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fichero-a-cargar-si-no-soporte.js'</span><span style="color: #339933;">,</span>
  complete<span style="color: #339933;">:</span> <span style="color: #3366CC;">'cosas-a-hacer-siempre.js'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Es decir, se testea la capacidad de <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a>/<a
href="http://www.manualweb.net/tutorial-css/" title="Manual de CSS">CSS3</a> que queramos cubrir. Si hay soporte se cargan los ficheros <a
href="http://www.manualweb.net/tutorial-javascript/" title="Tutorial de Javascript">Javascript</a> o <a
href="http://www.manualweb.net/tutorial-css/" title="Manual de CSS">CSS3</a> que haya en la parte del yep. Si no se soporta la propiedad testeada, se cargan  los ficheros del nope. Y siempre, pase lo que pase, se carga lo que haya en complete.</p><p>Nosotros vamos a testear la propiedad Modernizr.input.placeholder que valida si hay soporte de placeholders. En el caso de que no lo haya cargamos el plugin 'jquery.placeholder.js' y lo inicializamos.</p><p>Para inicializar el plugin tendremos que ejecutar la siguiente línea de código:</p><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input, textarea&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>El código del como utilizar un polyfill en <a
href="http://www.manualweb.net/tutorial-modernizr/" title="Manual de Modernizr">Modernizr</a> nos quedaría de la siguiente forma:</p><pre class="javascript" style="font-family:monospace;">Modernizr.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        test<span style="color: #339933;">:</span>Modernizr.<span style="color: #660066;">input</span>.<span style="color: #660066;">placeholder</span><span style="color: #339933;">,</span>
        nope<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'http://lineadecodigo.com/js/jquery/jquery.js'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'http://lineadecodigo.com/js/jquery/plugins/jquery.placeholder.min.js'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'placeholder.js'</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>En placeholder.js hemos metido la inicialización del plugin.</p><p>Esperamos que se haya entendido el concepto del polyfill en <a
href="http://www.manualweb.net/tutorial-modernizr/" title="Manual de Modernizr">Modernizr</a> y cómo cargarlos. En vuestro caso, ¿qué polyfills estás utilizando?<strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/jquery/crear-un-slider-con-jquery/" rel="bookmark" title="Febrero 19, 2012">Crear un slider con jQuery</a></li><li><a
href="http://lineadecodigo.com/javascript/modernizr-y-las-capacidades-html5-y-css3/" rel="bookmark" title="Enero 3, 2012">Modernizr y las capacidades HTML5 y CSS3</a></li><li><a
href="http://lineadecodigo.com/jquery/utilizar-placeholder-con-jquery/" rel="bookmark" title="Febrero 16, 2012">Utilizar Placeholder con jQuery</a></li><li><a
href="http://lineadecodigo.com/html5/placeholder-marcadores-de-posicion-en-html5/" rel="bookmark" title="Enero 12, 2011">PlaceHolder: Marcadores de posición en HTML5</a></li><li><a
href="http://lineadecodigo.com/javascript/jseclipse/" rel="bookmark" title="Febrero 10, 2007">JSEclipse</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/RP_Z0X6qWtOa5khUSjkWxG5_FDA/0/da"><img src="http://feedads.g.doubleclick.net/~a/RP_Z0X6qWtOa5khUSjkWxG5_FDA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/RP_Z0X6qWtOa5khUSjkWxG5_FDA/1/da"><img src="http://feedads.g.doubleclick.net/~a/RP_Z0X6qWtOa5khUSjkWxG5_FDA/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=gjp-oIVk4SI:JrAb-oZtpuw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=gjp-oIVk4SI:JrAb-oZtpuw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=gjp-oIVk4SI:JrAb-oZtpuw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=gjp-oIVk4SI:JrAb-oZtpuw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=gjp-oIVk4SI:JrAb-oZtpuw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=gjp-oIVk4SI:JrAb-oZtpuw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=gjp-oIVk4SI:JrAb-oZtpuw:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/gjp-oIVk4SI" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/javascript/como-utilizar-un-polyfill-con-modernizr/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://lineadecodigo.com/javascript/como-utilizar-un-polyfill-con-modernizr/</feedburner:origLink></item> <item><title>Utilizar Placeholder con jQuery</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/XDVHQTHtIU8/</link> <comments>http://lineadecodigo.com/jquery/utilizar-placeholder-con-jquery/#comments</comments> <pubDate>Thu, 16 Feb 2012 07:00:57 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[html5]]></category> <category><![CDATA[placeholder]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[ready]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3850</guid> <description><![CDATA[Seguro que alguno de vosotros ha leido nuestro artículo que cuenta como utilizar un placeholder con HTML5. Esto nos posibilita el poner un texto dentro de un campo de un formulario para orientar al usuario sobre que contenido insertar en dicho campo. Si bien, uno de los problemas que nos plantea el uso de ciertas [...]]]></description> <content:encoded><![CDATA[<p>Seguro que alguno de vosotros ha leido nuestro <a
href="http://lineadecodigo.com/html5/placeholder-marcadores-de-posicion-en-html5/" title="Cómo crear un placeholder con HTML5">artículo que cuenta como utilizar un placeholder con HTML5</a>. Esto nos posibilita el poner un texto dentro de un campo de un formulario para orientar al usuario sobre que contenido insertar en dicho campo.</p><p>Si bien, uno de los problemas que nos plantea el uso de ciertas propiedades <a
href="http://www.manualweb.net/tutorial-html5/" title="Tutorial de HTML5">HTML5</a> es la falta de implementación por parte de ciertos navegadores. Es por ello que la experiencia del usuario de esos navegadores puede ser diferente a la del resto.</p><p>Si queremos utilizar <a
href="http://www.w3api.com/wiki/HTML5:INPUT.placeholder" title="Atributo placeholder en HTML5">placeholders</a> sin <a
href="http://www.manualweb.net/tutorial-html5/" title="Tutorial de HTML5">HTML5</a> podemos recurrir a un <a
href="https://github.com/mathiasbynens/jquery-placeholder" title="Plugin jQuery para soporte de placeholders">plugin de jQuery</a>. Mediante el uso de <a
href="http://www.manualweb.net/tutorial-jquery/" title="Manual de jQuery">jQuery</a> y este plugin será muy sencillo poder utilizar un <a
href="http://www.w3api.com/wiki/HTML5:INPUT.placeholder" title="Atributo placeholder en HTML5">placeholders</a>. Además es que la forma en la que utilicemos el <a
href="http://www.w3api.com/wiki/HTML5:INPUT.placeholder" title="Atributo placeholder en HTML5">placeholders</a> será la misma forma en la que lo utilizábamos en <a
href="http://www.manualweb.net/tutorial-html5/" title="Tutorial de HTML5">HTML5</a>.</p><p>Es decir, si queremos crear un <a
href="http://www.w3api.com/wiki/HTML5:INPUT.placeholder" title="Atributo placeholder en HTML5">placeholders</a> pondremos lo siguiente:</p><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a> <a href="http://w3api.com/wiki/HTML:for"><span style="color: #000066;">for</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;texto&quot;</span>&gt;</span>Nombre: <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:INPUT"><span style="color: #000000; font-weight: bold;">input</span></a> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;texto&quot;</span> placeholder<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Inserte su nombre&quot;</span> <a href="http://w3api.com/wiki/HTML:size"><span style="color: #000066;">size</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre><p>Para poder utilizar el <a
href="http://www.w3api.com/wiki/HTML5:INPUT.placeholder" title="Atributo placeholder en HTML5">placeholders</a> con <a
href="http://www.manualweb.net/tutorial-jquery/" title="Manual de jQuery">jQuery</a> tendremos que hacer varias cosas. La primera será instanciar <a
href="http://www.manualweb.net/tutorial-jquery/" title="Manual de jQuery">jQuery</a> e instanciar el <a
href="https://github.com/mathiasbynens/jquery-placeholder" title="Plugin jQuery para soporte de placeholders">plugin de jQuery</a>.</p><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:SCRIPT"><span style="color: #000000; font-weight: bold;">script</span></a> <a href="http://w3api.com/wiki/HTML:src"><span style="color: #000066;">src</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:SCRIPT"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:SCRIPT"><span style="color: #000000; font-weight: bold;">script</span></a> <a href="http://w3api.com/wiki/HTML:src"><span style="color: #000066;">src</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.placeholder.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:SCRIPT"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span></pre><p>Y el siguiente paso inicializar el <a
href="https://github.com/mathiasbynens/jquery-placeholder" title="Plugin jQuery para soporte de placeholders">plugin de jQuery</a>. En este caso el código de incialización es:</p><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input, textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Si bien, deberemos de esperar a tener cargada la página. Por ello recurriremos al método <a
href="http://www.w3api.com/wiki/jQuery:Ready()" title="Método ready de jQuery">ready()</a> de <a
href="http://www.manualweb.net/tutorial-jquery/" title="Manual de jQuery">jQuery</a>.</p><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input, textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre><p>Con un <a
href="https://github.com/mathiasbynens/jquery-placeholder" title="Plugin jQuery para soporte de placeholders">plugin de jQuery</a> y unas pocas líneas de código tenemos la capacidad de dar soporte a los placeholders de <a
href="http://www.manualweb.net/tutorial-html5/" title="Tutorial de HTML5">HTML5</a>.</p><p>Te puedes descargar el <a
href="https://github.com/mathiasbynens/jquery-placeholder" title="Plugin jQuery para soporte de placeholders">plugin jQuery</a> desde <a
href="https://github.com/mathiasbynens/jquery-placeholder" title="Plugin jQuery para placeholders">https://github.com/mathiasbynens/jquery-placeholder</a>.<strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/javascript/como-utilizar-un-polyfill-con-modernizr/" rel="bookmark" title="Febrero 17, 2012">Como utilizar un Polyfill con Modernizr</a></li><li><a
href="http://lineadecodigo.com/jquery/crear-un-slider-con-jquery/" rel="bookmark" title="Febrero 19, 2012">Crear un slider con jQuery</a></li><li><a
href="http://lineadecodigo.com/html5/placeholder-marcadores-de-posicion-en-html5/" rel="bookmark" title="Enero 12, 2011">PlaceHolder: Marcadores de posición en HTML5</a></li><li><a
href="http://lineadecodigo.com/jquery/seleccionar-un-texto-solo-si-no-ha-cambiado/" rel="bookmark" title="Octubre 11, 2011">Seleccionar un texto solo si no ha cambiado</a></li><li><a
href="http://lineadecodigo.com/jquery/seleccionar-texto-al-posicionarse-en-un-campo/" rel="bookmark" title="Septiembre 23, 2011">Seleccionar texto al posicionarse en un campo</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/Yu_m8lqBpY3c6A-NuRVMfTUSuQ0/0/da"><img src="http://feedads.g.doubleclick.net/~a/Yu_m8lqBpY3c6A-NuRVMfTUSuQ0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Yu_m8lqBpY3c6A-NuRVMfTUSuQ0/1/da"><img src="http://feedads.g.doubleclick.net/~a/Yu_m8lqBpY3c6A-NuRVMfTUSuQ0/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=XDVHQTHtIU8:egqAHC4gWc8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=XDVHQTHtIU8:egqAHC4gWc8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=XDVHQTHtIU8:egqAHC4gWc8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=XDVHQTHtIU8:egqAHC4gWc8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=XDVHQTHtIU8:egqAHC4gWc8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=XDVHQTHtIU8:egqAHC4gWc8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=XDVHQTHtIU8:egqAHC4gWc8:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/XDVHQTHtIU8" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/jquery/utilizar-placeholder-con-jquery/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://lineadecodigo.com/jquery/utilizar-placeholder-con-jquery/</feedburner:origLink></item> <item><title>Menú Contextual en HTML5</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/_KYRvFqzNpw/</link> <comments>http://lineadecodigo.com/html5/menu-contextual-en-html5/#comments</comments> <pubDate>Tue, 14 Feb 2012 20:00:36 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[HTML5]]></category> <category><![CDATA[contextmenu]]></category> <category><![CDATA[icon]]></category> <category><![CDATA[label]]></category> <category><![CDATA[menu]]></category> <category><![CDATA[menu contextual]]></category> <category><![CDATA[menuitem]]></category> <category><![CDATA[section]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3835</guid> <description><![CDATA[Una de las cosas que no está todavía soportada por los navegadores web respecto al HTML5 son los menús contextuales. A día de hoy solo Firefox 8 y superiores dan soporte al menú contextual en HTML5. Pero, ¿qué es un menú contextual? Un menú contextual es aquel menú asociado a una zona de la página [...]]]></description> <content:encoded><![CDATA[<p>Una de las cosas que no está todavía soportada por los navegadores web respecto al <a
title="Tutorial de HTML5" href="http://www.manualweb.net/tutorial-html5/">HTML5</a> son los menús contextuales. A día de hoy solo <a
href="http://www.ayudaenlaweb.com/navegadores/que-es-firefox/" title="Qué es Firefox">Firefox 8</a> y superiores dan soporte al menú contextual en <a
title="Tutorial de HTML5" href="http://www.manualweb.net/tutorial-html5/">HTML5</a>.</p><p>Pero, ¿qué es un menú contextual? Un menú contextual es aquel menú asociado a una zona de la página y el cual tenemos disponible mediante el botón derecho del ratón.</p><p>Lo primero de todo será saber cómo se define un menú contextual. Para ello vamos a necesitar el <a
href="http://w3api.com/wiki/HTML5:MENU" title="Elemento MENU de HTML5">elemento menú</a>.</p><pre class="html4strict" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&lt;menu <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;colorMenu&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>menu&gt;</span>
&nbsp;</pre><p>Lo importante en el caso de estar creando un menú contextual es que el tipo del menú es "context". Otros valores son "toolbar" o "list".</p><p>Lo siguiente que haremos será definir los diferentes items o elementos que tendrá el menú. En este caso utilizamos el elemento menuitem para dar de alta cada uno de ellos.</p><pre class="html4strict" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&lt;menu <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;context&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;colorMenu&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;menuitem <a href="http://w3api.com/wiki/HTML:label"><span style="color: #000066;">label</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Rojo&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rojo&quot;</span> icon<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rojo.png&quot;</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span>menuitem&gt;</span>
<span style="color: #009900;">&lt;menuitem <a href="http://w3api.com/wiki/HTML:label"><span style="color: #000066;">label</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Verde&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;verde&quot;</span> icon<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;verde.png&quot;</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span>menuitem&gt;</span>
<span style="color: #009900;">&lt;menuitem <a href="http://w3api.com/wiki/HTML:label"><span style="color: #000066;">label</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Azul&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;azul&quot;</span> icon<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;azul.png&quot;</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span>menuitem&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>menu&gt;</span>
&nbsp;</pre><p>Vemos que cada menuitem lleva asociado un atributo label, que será el texto que aparezca en la opción del menú, un id y un icono, el cual definimos mediante el atributo icon. Ya solo nos quedará decidir dónde se va a lanzar el menú. Sobre que parte de la página se podrá ver este menú contextual en <a
title="Tutorial de HTML5" href="http://www.manualweb.net/tutorial-html5/">HTML5</a>. Para ello utilizamos el atributo general contextmenu, al cual deberemos de pasar el ID del menú que acabamos de crear. Que queremos aplicar el menú sobre una sección de la página escribiremos:</p><pre class="html4strict" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&lt;section contextmenu<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;colorMenu&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;miseccion&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span>
&nbsp;</pre><p>Que lo queremos aplicar sobre un <a
href="http://w3api.com/wiki/HTML5:INPUT" title="Elemento INPUT de HTML5">campo de input</a>, pues escribirmos lo siguiente:</p><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a> <a href="http://w3api.com/wiki/HTML:for"><span style="color: #000066;">for</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color&quot;</span>&gt;</span>Color:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:INPUT"><span style="color: #000000; font-weight: bold;">input</span></a> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color&quot;</span> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> contextmenu<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;colorMenu&quot;</span>&gt;</span>
&nbsp;</pre><p>Ya solo nos quedará pulsar con el botón derecho sobre la zona del menú contextual para ver el efecto.</p><p><a
href="http://lineadecodigo.com/wp-content/uploads/2012/02/contextmenu.png"><img
src="http://lineadecodigo.com/wp-content/uploads/2012/02/contextmenu.png" alt="" title="contextmenu" width="500" height="372" class="aligncenter size-full wp-image-3840" /></a></p><p>Sobre los menús contextuales podemos manejar los eventos como sobre cualquier otro elemento de la página. Así podemos añadir el siguiente código en <a
href="http://www.manualweb.net/tutorial-javascript/" title="Manual de Javascript">Javascript</a> para controlar el click sobre las opciones del menú contextual.</p><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> campo <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> color <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;colorMenu&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
color.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ev<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	campo.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> ev.<span style="color: #660066;">target</span>.<span style="color: #660066;">label</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p><strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/javascript/cambiar-estilos-dinamicamente/" rel="bookmark" title="Septiembre 12, 2009">Cambiar estilos dinámicamente</a></li><li><a
href="http://lineadecodigo.com/jquery/seleccionar-el-texto-de-un-campo/" rel="bookmark" title="Septiembre 21, 2011">Seleccionar el texto de un campo</a></li><li><a
href="http://lineadecodigo.com/html5/datalist-en-html5/" rel="bookmark" title="Febrero 1, 2012">DataList en HTML5</a></li><li><a
href="http://lineadecodigo.com/jquery/acceder-a-un-campo-de-formulario-con-jquery/" rel="bookmark" title="Junio 7, 2011">Acceder a un campo de formulario con jQuery</a></li><li><a
href="http://lineadecodigo.com/css/poner-un-fondo-en-mi-pagina-web/" rel="bookmark" title="Mayo 28, 2011">Poner un fondo en mi página web</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/7vhesDj8ActccU-2UL-OHj-Wjfg/0/da"><img src="http://feedads.g.doubleclick.net/~a/7vhesDj8ActccU-2UL-OHj-Wjfg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/7vhesDj8ActccU-2UL-OHj-Wjfg/1/da"><img src="http://feedads.g.doubleclick.net/~a/7vhesDj8ActccU-2UL-OHj-Wjfg/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=_KYRvFqzNpw:98SwvC-FbD0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=_KYRvFqzNpw:98SwvC-FbD0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=_KYRvFqzNpw:98SwvC-FbD0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=_KYRvFqzNpw:98SwvC-FbD0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=_KYRvFqzNpw:98SwvC-FbD0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=_KYRvFqzNpw:98SwvC-FbD0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=_KYRvFqzNpw:98SwvC-FbD0:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/_KYRvFqzNpw" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/html5/menu-contextual-en-html5/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://lineadecodigo.com/html5/menu-contextual-en-html5/</feedburner:origLink></item> <item><title>Crear un Canvas en HTML5</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/Lp7PuEgOs_M/</link> <comments>http://lineadecodigo.com/html5/crear-un-canvas-en-html5/#comments</comments> <pubDate>Tue, 07 Feb 2012 07:00:08 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[HTML5]]></category> <category><![CDATA[2d]]></category> <category><![CDATA[3d]]></category> <category><![CDATA[Canvas]]></category> <category><![CDATA[CanvasRenderingContext2D]]></category> <category><![CDATA[fillRect]]></category> <category><![CDATA[fillStyle]]></category> <category><![CDATA[getContext]]></category> <category><![CDATA[getElementById]]></category> <category><![CDATA[height]]></category> <category><![CDATA[id]]></category> <category><![CDATA[width]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3829</guid> <description><![CDATA[El canvas es un elemento que aparece nuevo en HTML5 y que nos permitirá la gestión de gráficos. Así podremos dibujar gráficos, crear foto composiciones, realizar animaciones,... Para crear un canvas en HTML5 tenemos que utilizar el elemento CANVAS. &#60;canvas&#62; Contenido alternativo &#60;/canvas&#62; A un elemento CANVAS podemos darle un alto y ancho mediante los [...]]]></description> <content:encoded><![CDATA[<p>El canvas es un elemento que aparece nuevo en <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a> y que nos permitirá la gestión de gráficos. Así podremos dibujar gráficos, crear foto composiciones, realizar animaciones,...</p><p>Para crear un canvas en <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a> tenemos que utilizar el elemento <a
href="http://www.w3api.com/wiki/HTML5:CANVAS" title="Elemento CANVAS de HTML5">CANVAS</a>.</p><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;canvas&gt;</span>
  Contenido alternativo
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span></pre><p>A un elemento <a
href="http://www.w3api.com/wiki/HTML5:CANVAS" title="Elemento CANVAS de HTML5">CANVAS</a> podemos darle un alto y ancho mediante los atributos <a
href="http://www.w3api.com/wiki/HTML5:CANVAS.height" title="Atributo height del CANVAS">height</a> y <a
href="http://www.w3api.com/wiki/HTML5:CANVAS.width" title="Atributo width del CANVAS">width</a> respectivamente. Así como darle un identificador mediante el <a
href="http://www.w3api.com/wiki/HTML5:Id" title="Atributo id de HTML5">atributo id</a>.</p><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;canvas <a href="http://w3api.com/wiki/HTML:height"><span style="color: #000066;">height</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300px&quot;</span> <a href="http://w3api.com/wiki/HTML:width"><span style="color: #000066;">width</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300px&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;micanvas&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span></pre><p>En el caso de que no indiquemos las dimesiones, estas serán de 300x150.</p><p>Una vez que tenemos nuestro "lienzo" vamos a dibujar algún gráfico. Para ello utilizaremos el lenguaje <a
href="http://www.manualweb.net/tutorial-javascript/" title="Tutorial de Javascript">Javascript</a>. Así lo primero que haremos será obtener la referencia sobre el <a
href="http://www.w3api.com/wiki/HTML5:CANVAS" title="Elemento CANVAS de HTML5">CANVAS</a> mediante un <a
href="http://www.w3api.com/wiki/DOM:Document.getElementById()" title="Método .getElementById del DOM">getElementById()</a>.</p><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;micanvas&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Dentro de un <a
href="http://www.w3api.com/wiki/HTML5:CANVAS" title="Elemento CANVAS de HTML5">CANVAS</a> podemos volcar varios contextos. Lo que son conocidos como contextos de renderizado. Así podremos tener contextos 2D y 3D. Estos últimos todavía en fase experimental. El método <a
href="http://www.w3api.com/wiki/DOM:HTMLCanvasElement.getContext()" title="Método .getContext() del CANVAS">.getContext()</a> sobre el <a
href="http://www.w3api.com/wiki/HTML5:CANVAS" title="Elemento CANVAS de HTML5">CANVAS</a> nos permitirá crear un nuevo contexto.</p><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;micanvas&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Ahora ya pasaremos a dibujar gráficos. Así, con el manejo de una propiedad: <a
href="http://www.w3api.com/wiki/DOM:CanvasRenderingContext2D.fillStyle" title="Atributo fillStyle del Contexto del CANVAS">.fillStyle</a> y un método <a
href="http://www.w3api.com/wiki/DOM:CanvasRenderingContext2D.fillRect()" title="Método fillRect sobre un contexto del CANVAS">.fillRect()</a> podemos crear rectángulos de colores. En el caso de <a
href="http://www.w3api.com/wiki/DOM:CanvasRenderingContext2D.fillStyle" title="Atributo fillStyle del Contexto del CANVAS">.fillStyle</a> recibe como parámetro un color definido en formato RGB y en el caso de <a
href="http://www.w3api.com/wiki/DOM:CanvasRenderingContext2D.fillRect()" title="Método fillRect sobre un contexto del CANVAS">.fillRect()</a> las coordenadas de los vertices superior izquierdo, así como el alto y ancho.</p><p>Así nos quedará el código que insertará gráficos al crear nuestro primer canvas con <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a>.</p><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;micanvas&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ctx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rgb(255,0,0)&quot;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ctx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rgb(0,255,0)&quot;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">60</span><span style="color: #339933;">,</span><span style="color: #CC0000;">60</span><span style="color: #339933;">,</span><span style="color: #CC0000;">140</span><span style="color: #339933;">,</span><span style="color: #CC0000;">140</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ctx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rgb(0,0,255)&quot;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span><span style="color: #CC0000;">180</span><span style="color: #339933;">,</span><span style="color: #CC0000;">180</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p><strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/javascript/modernizr-y-las-capacidades-html5-y-css3/" rel="bookmark" title="Enero 3, 2012">Modernizr y las capacidades HTML5 y CSS3</a></li><li><a
href="http://lineadecodigo.com/javascript/documentgetelementbyid/" rel="bookmark" title="Junio 25, 2007">document.getElementById</a></li><li><a
href="http://lineadecodigo.com/html5/parar-la-descarga-de-un-video-en-html5/" rel="bookmark" title="Enero 21, 2012">Parar la descarga de un vídeo en HTML5</a></li><li><a
href="http://lineadecodigo.com/svg/dibujar-una-elipse-en-svg/" rel="bookmark" title="Enero 11, 2008">Dibujar una elipse en SVG</a></li><li><a
href="http://lineadecodigo.com/javascript/crear-elementos-html-con-javascript/" rel="bookmark" title="Septiembre 9, 2007">Crear elementos HTML con JavaScript</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/Ofrepk9WUt6EBK9XSbBQ26u1fIM/0/da"><img src="http://feedads.g.doubleclick.net/~a/Ofrepk9WUt6EBK9XSbBQ26u1fIM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Ofrepk9WUt6EBK9XSbBQ26u1fIM/1/da"><img src="http://feedads.g.doubleclick.net/~a/Ofrepk9WUt6EBK9XSbBQ26u1fIM/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Lp7PuEgOs_M:PNLCa0xix8g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Lp7PuEgOs_M:PNLCa0xix8g:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=Lp7PuEgOs_M:PNLCa0xix8g:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Lp7PuEgOs_M:PNLCa0xix8g:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=Lp7PuEgOs_M:PNLCa0xix8g:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Lp7PuEgOs_M:PNLCa0xix8g:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Lp7PuEgOs_M:PNLCa0xix8g:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/Lp7PuEgOs_M" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/html5/crear-un-canvas-en-html5/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://lineadecodigo.com/html5/crear-un-canvas-en-html5/</feedburner:origLink></item> <item><title>Tiempo visualizado del vídeo en HTML5</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/1f-4Ei1lEDo/</link> <comments>http://lineadecodigo.com/html5/tiempo-visualizado-del-video-en-html5/#comments</comments> <pubDate>Mon, 06 Feb 2012 07:00:11 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[HTML5]]></category> <category><![CDATA[addEventListener]]></category> <category><![CDATA[currentTime]]></category> <category><![CDATA[segundos]]></category> <category><![CDATA[timeupdate]]></category> <category><![CDATA[video]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3823</guid> <description><![CDATA[Seguimos con el análisis del manejo de vídeos en HTML5, así como con el manejo del elemento DOM HTMLMediaElement. En este caso vamos a ver como podemos ir viendo el tiempo visualizado del vídeo en HTML5. Es decir, según vaya avanzando la visualización del vídeo, calcular los segundos que hayan transcurrido de la visualización. Lo [...]]]></description> <content:encoded><![CDATA[<p>Seguimos con el análisis del manejo de vídeos en <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a>, así como con el manejo del <a
href="http://www.w3api.com/wiki/DOM:HTMLMediaElement" title="Elemento del DOM HTMLMediaElement">elemento DOM HTMLMediaElement</a>. En este caso vamos a ver como podemos ir viendo el tiempo visualizado del vídeo en <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual de HTML5">HTML5</a>. Es decir, según vaya avanzando la visualización del vídeo, calcular los segundos que hayan transcurrido de la visualización.</p><p>Lo primero será poner el vídeo en nuestra página web.</p><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;video <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mivideo&quot;</span> controls&gt;</span>
  <span style="color: #009900;">&lt;source <a href="http://w3api.com/wiki/HTML:src"><span style="color: #000066;">src</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://easyhtml5video.com/images/happyfit2.ogv&quot;</span> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;video/ogg&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>source&gt;</span>
  Tu navegador no soporta el elemento <span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:CODE"><span style="color: #000000; font-weight: bold;">code</span></a>&gt;</span>video<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:CODE"><span style="color: #000000; font-weight: bold;">code</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>video&gt;</span></pre><p>Cuándo el usuario pulse al play se irán sucediendo una serie de eventos. Uno de los eventos importantes es <a
href="http://www.w3api.com/wiki/DOM:HTMLMediaElement.ontimeupdate" title="Evento timeupdate del elemento HTMLMediaElement">timeupdate</a>. Dicho evento se envía progresivamente según avanza la visualización del vídeo. Así que tendremos que crear un listener sobre dicho evento en el vídeo.</p><pre class="javascript" style="font-family:monospace;"> <span style="color: #003366; font-weight: bold;">var</span> v <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mivideo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 v.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;timeupdate&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ev<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  ...
 <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Cuándo se ejecute el método asociado al listener deberemos de acceder al atributo <a
href="http://www.w3api.com/wiki/DOM:HTMLMediaElement.currentTime" title="Atributo currentTime del elemento HTMLMediaElement">.currentTime</a> del <a
href="http://www.w3api.com/wiki/DOM:HTMLMediaElement" title="Elemento del DOM HTMLMediaElement">HTMLMediaElement</a>, ya que este atributo es el que contiene el tiempo transcurrido del vídeo. Este tiempo será en segundos.</p><p>Lo que nosotros hacemos es volcar el contenido del atributo <a
href="http://www.w3api.com/wiki/DOM:HTMLMediaElement.currentTime" title="Atributo currentTime del elemento HTMLMediaElement">.currentTime</a> sobre una capa. Este contenido se irá actualizando cada vez que se lance el evento <a
href="http://www.w3api.com/wiki/DOM:HTMLMediaElement.ontimeupdate" title="Evento timeupdate del elemento HTMLMediaElement">timeupdate</a> en el vídeo.</p><pre class="javascript" style="font-family:monospace;">v.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;timeupdate&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ev<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tiemposegundos&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> v.<span style="color: #660066;">currentTime</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Si queremos "dejarlo bonito" podemos convertir el tiempo en segundos en un formato reloj, igual que explicábamos en el artículo <a
href="http://lineadecodigo.com/javascript/convertir-segundos-en-formato-hora-con-javascript/" title="Convertir segundos en formato hora con Javascript">Convertir segundos en formato hora con Javascript</a>.</p><p>Nosotros hemos metido este código dentro de una función que la hemos llamado hora, la cual recibe una cantidad de segundos, los cuales los devuelve en un formato hh:mm:ss.</p><pre class="javascript" style="font-family:monospace;"> <span style="color: #003366; font-weight: bold;">function</span> hora<span style="color: #009900;">&#40;</span>segundos<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> d<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span>segundos<span style="color: #339933;">*</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// Ajuste de las 23 horas</span>
  <span style="color: #003366; font-weight: bold;">var</span> hora <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>d.<span style="color: #660066;">getHours</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span><span style="color: #CC0000;">23</span><span style="color: #339933;">:</span>d.<span style="color: #660066;">getHours</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> hora <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>hora<span style="color: #339933;">&lt;</span><span style="color: #CC0000;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>hora<span style="color: #339933;">:</span>hora<span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> minuto <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>d.<span style="color: #660066;">getMinutes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>d.<span style="color: #660066;">getMinutes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>d.<span style="color: #660066;">getMinutes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> segundo <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>d.<span style="color: #660066;">getSeconds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>d.<span style="color: #660066;">getSeconds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>d.<span style="color: #660066;">getSeconds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> hora<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;:&quot;</span><span style="color: #339933;">+</span>minuto<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;:&quot;</span><span style="color: #339933;">+</span>segundo<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre><p>Ya solo nos quedará invocar a esta función desde el listener:</p><pre class="javascript" style="font-family:monospace;">v.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;timeupdate&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ev<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tiemposegundos&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> v.<span style="color: #660066;">currentTime</span><span style="color: #339933;">;</span>
   document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tiempo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> hora<span style="color: #009900;">&#40;</span>v.<span style="color: #660066;">currentTime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p><strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/html5/tiempo-total-de-un-video-html5/" rel="bookmark" title="Febrero 2, 2012">Tiempo total de un vídeo HTML5</a></li><li><a
href="http://lineadecodigo.com/javascript/convertir-segundos-en-formato-hora-con-javascript/" rel="bookmark" title="Enero 23, 2012">Convertir segundos en formato hora con Javascript</a></li><li><a
href="http://lineadecodigo.com/javascript/convertir-una-cadena-a-fecha-en-javascript/" rel="bookmark" title="Enero 29, 2012">Convertir una cadena a fecha en Javascript</a></li><li><a
href="http://lineadecodigo.com/html5/elemento-rango-en-formularios-html5/" rel="bookmark" title="Enero 31, 2012">Elemento rango en formularios HTML5</a></li><li><a
href="http://lineadecodigo.com/javascript/crear-eventos-con-javascript/" rel="bookmark" title="Septiembre 29, 2007">Crear eventos con JavaScript</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/dfnPkE5kGHcfZIx5YRAkMLeiSss/0/da"><img src="http://feedads.g.doubleclick.net/~a/dfnPkE5kGHcfZIx5YRAkMLeiSss/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/dfnPkE5kGHcfZIx5YRAkMLeiSss/1/da"><img src="http://feedads.g.doubleclick.net/~a/dfnPkE5kGHcfZIx5YRAkMLeiSss/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=1f-4Ei1lEDo:nJbHVpTADEk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=1f-4Ei1lEDo:nJbHVpTADEk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=1f-4Ei1lEDo:nJbHVpTADEk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=1f-4Ei1lEDo:nJbHVpTADEk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=1f-4Ei1lEDo:nJbHVpTADEk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=1f-4Ei1lEDo:nJbHVpTADEk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=1f-4Ei1lEDo:nJbHVpTADEk:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/1f-4Ei1lEDo" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/html5/tiempo-visualizado-del-video-en-html5/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <enclosure url="http://easyhtml5video.com/images/happyfit2.ogv" length="10220659" type="video/ogg" /> <feedburner:origLink>http://lineadecodigo.com/html5/tiempo-visualizado-del-video-en-html5/</feedburner:origLink></item> <item><title>Autofoco a un campo con HTML5</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/3bo-Qlv0Mrs/</link> <comments>http://lineadecodigo.com/html5/autofoco-a-un-campo-con-html5/#comments</comments> <pubDate>Sun, 05 Feb 2012 15:00:08 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[HTML5]]></category> <category><![CDATA[autofocus]]></category> <category><![CDATA[focus]]></category> <category><![CDATA[Form]]></category> <category><![CDATA[input]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3814</guid> <description><![CDATA[Antes de tener la especificación de HTML5 si queríamos realizar un autofoco a un campo, es decir, que al cargar una página el foco del cursor se pusiese en un campo de un formulario, teníamos que utilizar código Javascript. Ahora, gracias a HTML5, podemos acometer esta labor de una forma sencilla. Lo primero será definir [...]]]></description> <content:encoded><![CDATA[<p>Antes de tener la especificación de <a
title="Manual de HTML5" href="http://www.manualweb.net/tutorial-html5/">HTML5</a> si queríamos realizar un autofoco a un campo, es decir, que al cargar una página el foco del cursor se pusiese en un campo de un formulario, <a
title="Usar focus() en Javascript" href="http://lineadecodigo.com/javascript/hacer-foco-en-un-campo-de-la-pagina-usando-javascript/">teníamos que utilizar código Javascript</a>.<br
/> Ahora, gracias a <a
title="Manual de HTML5" href="http://www.manualweb.net/tutorial-html5/">HTML5</a>, podemos acometer esta labor de una forma sencilla.</p><p>Lo primero será definir el formulario. En nuestro caso tendrá dos simples campos de entrada de texto:</p><pre class="html4strict" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:FORM"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span>
  <span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a> <a href="http://w3api.com/wiki/HTML:for"><span style="color: #000066;">for</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nombre&quot;</span>&gt;</span>¿Cómo te llamas?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:INPUT"><span style="color: #000000; font-weight: bold;">input</span></a> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nombre&quot;</span> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a> <a href="http://w3api.com/wiki/HTML:for"><span style="color: #000066;">for</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;edad&quot;</span>&gt;</span>¿Cuántos años tienes?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:INPUT"><span style="color: #000000; font-weight: bold;">input</span></a> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;edad&quot;</span> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:FORM"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span>
&nbsp;</pre><p>Si lo que queremos es que el autofoco se realice sobre el campo <a
title="Elemento INPUT de HTML5" href="http://www.w3api.com/wiki/HTML5:INPUT">INPUT</a> nombre, le añadiremos el atributo <a
title="Atributo autofocus del elemento INPUT" href="http://www.w3api.com/wiki/HTML5:INPUT.autofocus">autofocus</a>. Quedándonos el siguiente código:</p><pre class="html4strict" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:FORM"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span>
  <span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a> <a href="http://w3api.com/wiki/HTML:for"><span style="color: #000066;">for</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nombre&quot;</span>&gt;</span>¿Cómo te llamas?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:INPUT"><span style="color: #000000; font-weight: bold;">input</span></a> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nombre&quot;</span> autofoucs <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a> <a href="http://w3api.com/wiki/HTML:for"><span style="color: #000066;">for</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;edad&quot;</span>&gt;</span>¿Cuántos años tienes?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:INPUT"><span style="color: #000000; font-weight: bold;">input</span></a> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;edad&quot;</span> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:FORM"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span>
&nbsp;</pre><blockquote><p>El atributo <a
title="Atributo autofocus del elemento INPUT" href="http://www.w3api.com/wiki/HTML5:INPUT.autofocus">autofocus</a> solo puede aplicarse sobre un único campo del formulario</p></blockquote><p>Solo tenemos que tener cuidado de una cosa y es que la especificación <a
title="Manual de HTML5" href="http://www.manualweb.net/tutorial-html5/">HTML5</a> todavía no está terminada ni implementada en todos los navegadores web. Es por ello que puede ser que no funcione correctamente. Las versiones mínimas en las que funciona son <a
title="Qué es Google Chrome" href="http://www.ayudaenlaweb.com/navegadores/que-es-google-chrome/">Chrome</a> 6, <a
title="Qué es Firefox" href="http://www.ayudaenlaweb.com/navegadores/que-es-firefox/">Firefox</a> 4, <a
title="Qué es Opera" href="http://www.ayudaenlaweb.com/navegadores/que-es-opera/">Opera</a> 11, <a
title="Qué es Safari" href="http://www.ayudaenlaweb.com/navegadores/que-es-safari/">Safari</a> 5 e <a
title="Qué es el Internet Explorer" href="http://www.ayudaenlaweb.com/navegadores/que-es-internet-explorer/">Internet Explorer</a> 10. Quizás la versión del <a
title="Qué es el Internet Explorer" href="http://www.ayudaenlaweb.com/navegadores/que-es-internet-explorer/">Internet Explorer</a> sea la que más problemas pueda ocasionarte.</p><p>En este caso podemos recurrir a la implementación en <a
title="Manual de Javascript" href="http://www.manualweb.net/tutorial-javascript/">Javascript</a>. En este caso vamos a crear mediante <a
title="Manual de Javascript" href="http://www.manualweb.net/tutorial-javascript/">Javascript</a> un elemento <a
title="Elemento INPUT de HTML5" href="http://www.w3api.com/wiki/HTML5:INPUT">INPUT</a> ficiticio y vamos a comprobar si este tiene el atributo autofocus o no. En caso de que no lo tenga lanzaremos el código <a
title="Manual de Javascript" href="http://www.manualweb.net/tutorial-javascript/">Javascript</a> con el método <a
title="Método focus() de Javascript" href="http://www.w3api.com/wiki/DOM:Element.focus()">.focus()</a></p><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autofocus&quot;</span> <span style="color: #000066; font-weight: bold;">in</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;nombre&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p><strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/javascript/hacer-foco-en-un-campo-de-la-pagina-usando-javascript/" rel="bookmark" title="Junio 13, 2007">Hacer foco en un campo de la página usando JavaScript</a></li><li><a
href="http://lineadecodigo.com/jquery/seleccionar-texto-al-posicionarse-en-un-campo/" rel="bookmark" title="Septiembre 23, 2011">Seleccionar texto al posicionarse en un campo</a></li><li><a
href="http://lineadecodigo.com/javascript/cambiar-el-valor-de-un-radio-group-dinamicamente/" rel="bookmark" title="Septiembre 19, 2009">Cambiar el valor de un radio group dinámicamente</a></li><li><a
href="http://lineadecodigo.com/jquery/seleccionar-un-texto-solo-si-no-ha-cambiado/" rel="bookmark" title="Octubre 11, 2011">Seleccionar un texto solo si no ha cambiado</a></li><li><a
href="http://lineadecodigo.com/html5/placeholder-marcadores-de-posicion-en-html5/" rel="bookmark" title="Enero 12, 2011">PlaceHolder: Marcadores de posición en HTML5</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/zQMFw2ds_sLgYJkPv9rOaUjqBE8/0/da"><img src="http://feedads.g.doubleclick.net/~a/zQMFw2ds_sLgYJkPv9rOaUjqBE8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/zQMFw2ds_sLgYJkPv9rOaUjqBE8/1/da"><img src="http://feedads.g.doubleclick.net/~a/zQMFw2ds_sLgYJkPv9rOaUjqBE8/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=3bo-Qlv0Mrs:5X64VmeNifY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=3bo-Qlv0Mrs:5X64VmeNifY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=3bo-Qlv0Mrs:5X64VmeNifY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=3bo-Qlv0Mrs:5X64VmeNifY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=3bo-Qlv0Mrs:5X64VmeNifY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=3bo-Qlv0Mrs:5X64VmeNifY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=3bo-Qlv0Mrs:5X64VmeNifY:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/3bo-Qlv0Mrs" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/html5/autofoco-a-un-campo-con-html5/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://lineadecodigo.com/html5/autofoco-a-un-campo-con-html5/</feedburner:origLink></item> <item><title>Controlar volumen de vídeo HTML5 con un Slider</title><link>http://feedproxy.google.com/~r/LineaDeCodigo/~3/Q_J686Pz30s/</link> <comments>http://lineadecodigo.com/html5/controlar-volumen-de-video-html5-con-un-slider/#comments</comments> <pubDate>Fri, 03 Feb 2012 21:00:53 +0000</pubDate> <dc:creator>Víctor Cuervo</dc:creator> <category><![CDATA[HTML5]]></category> <category><![CDATA[checkbox]]></category> <category><![CDATA[checked]]></category> <category><![CDATA[input]]></category> <category><![CDATA[max]]></category> <category><![CDATA[min]]></category> <category><![CDATA[slider]]></category> <category><![CDATA[step]]></category> <category><![CDATA[value]]></category> <category><![CDATA[video]]></category> <category><![CDATA[volume]]></category> <guid isPermaLink="false">http://lineadecodigo.com/?p=3806</guid> <description><![CDATA[En este ejemplo vamos a combinar varias cosas que hemos aprendido sobre el HTML5. Por un lado el manejo de los sliders para poder establecer un rango de valores mediante una barra de desplazamiento. Por otro el manejo de un vídeo en HTML5. Además aprenderemos una cosa nueva, que será el controlar el volumen del [...]]]></description> <content:encoded><![CDATA[<p>En este ejemplo vamos a combinar varias cosas que hemos aprendido sobre el <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual sobre HTML5">HTML5</a>. Por un lado <a
href="http://lineadecodigo.com/html5/elemento-rango-en-formularios-html5/" title="Manejo de los sliders y el elemento rango en HTML5">el manejo de los sliders para poder establecer un rango de valores mediante una barra de desplazamiento</a>. Por otro <a
href="http://lineadecodigo.com/html5/cargar-un-video-en-html5/" title="Manejo de un video en HTML5">el manejo de un vídeo en HTML5</a>. Además aprenderemos una cosa nueva, que será el controlar el volumen del vídeo con un slider.</p><p>Lo primero que haremos será poner en nuestra página los elementos <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual sobre HTML5">HTML5</a> que necesitemos, ya que el código <a
href="http://www.manualweb.net/tutorial-javascript/" title="Manual de Javascript">Javascript</a> que incorporemos será siempre no intrusivo.</p><p>El vídeo, mediante el elemento <a
href="http://w3api.com/wiki/HTML5:VIDEO" title="Elemento VIDEO de HTML5">VIDEO</a> será el siguiente:</p><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;video <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mivideo&quot;</span> controls&gt;</span>
  <span style="color: #009900;">&lt;source <a href="http://w3api.com/wiki/HTML:src"><span style="color: #000066;">src</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://easyhtml5video.com/images/happyfit2.ogv&quot;</span> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;video/ogg&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>source&gt;</span>
  Tu navegador no soporta el elemento <span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:CODE"><span style="color: #000000; font-weight: bold;">code</span></a>&gt;</span>video<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:CODE"><span style="color: #000000; font-weight: bold;">code</span></a>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>video&gt;</span></pre><p>Y el slider será mediante un <a
href="http://w3api.com/wiki/HTML5:INPUT" title="Elemento INPUT de HTML5">elemento input</a> y su tipo "range"</p><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a> <a href="http://w3api.com/wiki/HTML:for"><span style="color: #000066;">for</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;volumen&quot;</span>&gt;</span>Volumen: <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:INPUT"><span style="color: #000000; font-weight: bold;">input</span></a> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;range&quot;</span> min<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> max<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <a href="http://w3api.com/wiki/HTML:value"><span style="color: #000066;">value</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> step<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0.1&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;volumen&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://w3api.com/wiki/HTML:INPUT"><span style="color: #000000; font-weight: bold;">input</span></a> <a href="http://w3api.com/wiki/HTML:type"><span style="color: #000066;">type</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <a href="http://w3api.com/wiki/HTML:id"><span style="color: #000066;">id</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mute&quot;</span>&gt;&lt;<a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a> <a href="http://w3api.com/wiki/HTML:for"><span style="color: #000066;">for</span></a><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mute&quot;</span>&gt;</span>Mute<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://w3api.com/wiki/HTML:LABEL"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span></pre><p>Además hemos incorporado un checkbox para simular el mute. Es decir, para quitar el sonido al vídeo.</p><p>Lo primero, las referencias a los elementos:</p><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> mute <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mute&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> barra <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;volumen&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Sobre el tema de controlar el volumen del vídeo deberemos de saber que la propiedad que gestiona el volumen de un vídeo en <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual sobre HTML5">HTML5</a> es <a
href="http://w3api.com/wiki/DOM:HTMLMediaElement.volume" title="Atributo volume de HTMLMediaElement">.volume</a> del elemento HTMLMediaElement. Y que los valores que puede tomar dicha propiedad van desde el 0.0 hasta el 1.0 con saltos de 0.1. Algo importante ya que como vemos son los valores que hemos dado a las propiedades <a
href="http://w3api.com/wiki/HTML5:INPUT.min" title="Atributo min del elemento INPUT">min</a>, <a
href="http://w3api.com/wiki/HTML5:INPUT.max" title="Atributo max del elemento INPUT">max</a> y <a
href="http://w3api.com/wiki/HTML5:INPUT.step" title="Atributo step del slider">step</a> del slider.</p><p>Así la codificación ante un cambio del slider, es decir, ante que se produzca un evento change, será el asignar el valor del slider al volumen del vídeo.</p><pre class="javascript" style="font-family:monospace;">barra.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ev<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> v <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mivideo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  v.<span style="color: #660066;">volume</span> <span style="color: #339933;">=</span> ev.<span style="color: #660066;">target</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
  mute.<span style="color: #660066;">checked</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>Vemos en el código que el .value del slider se lo asignamos a la propiedad <a
href="http://w3api.com/wiki/DOM:HTMLMediaElement.volume" title="Atributo volume de HTMLMediaElement">.volume</a> del vídeo.</p><blockquote><p>Utilizamos <a
href="http://w3api.com/wiki/DOM:Element.addEventListener()" title="Méodo addEventListener">.addEventListener</a> para adjuntar la gestión de un evento a un elemento en concreto.</p></blockquote><p>Además hemos añadido el manejo del mute. es decir, si cambiamos el slider (movemos el volumen) se desactivará la casilla del mute.</p><p>Ahora vamos con el mute. Para esto gestionamos el evento change del checkbox. Cada vez que cambie el checkbox veremos que hacer. Pero antes de esto nos vamos a crear una variable que nos permite mantener la información del volumen. Esta nos servirá para que cuando desactivemos el mute, recuperemos la última posición del volumen. A esta variable la hemos llamado oldvolume.</p><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> oldvolume <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span></pre><p>Inicializada a 1, al igual que sucede con el volumen.<br
/> Ahora solo tenemos que jugar con el valor del checkbox. Su atributo .checked nos indicará si este está activo o no.</p><pre class="javascript" style="font-family:monospace;">mute.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ev<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> v <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mivideo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ev.<span style="color: #660066;">target</span>.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		oldvolume <span style="color: #339933;">=</span> v.<span style="color: #660066;">volume</span><span style="color: #339933;">;</span>
		v.<span style="color: #660066;">volume</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		barra.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		v.<span style="color: #660066;">volume</span> <span style="color: #339933;">=</span> oldvolume<span style="color: #339933;">;</span>
		barra.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> oldvolume<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><p>La lógica, la siguiente. Si está activado hay que apagar el volumen (atributo volume a 0 y el slider con un valor de 0), pero guardándonos la posición actual del volumen en la variable oldvolume.</p><p>Que el checkbox está desactivado, pues reponemos el valor de la variable oldvolume tanto al slider, como al atributo <a
href="http://w3api.com/wiki/DOM:HTMLMediaElement.volume" title="Atributo volume de HTMLMediaElement">.volume</a> del vídeo.</p><p>Con todo esto ya podemos controlar el volumen de vídeo <a
href="http://www.manualweb.net/tutorial-html5/" title="Manual sobre HTML5">HTML5</a> con un Slider.<strong>Similar Posts:</strong><ul
class="similar-posts"><li><a
href="http://lineadecodigo.com/javascript/contar-checkbox-activos-con-javascript/" rel="bookmark" title="Febrero 8, 2008">Contar checkbox activos con JavaScript</a></li><li><a
href="http://lineadecodigo.com/html5/elemento-rango-en-formularios-html5/" rel="bookmark" title="Enero 31, 2012">Elemento rango en formularios HTML5</a></li><li><a
href="http://lineadecodigo.com/jquery/cambios-en-un-combo-con-jquery/" rel="bookmark" title="Mayo 17, 2011">Cambios en un combo con jQuery</a></li><li><a
href="http://lineadecodigo.com/html5/tiempo-total-de-un-video-html5/" rel="bookmark" title="Febrero 2, 2012">Tiempo total de un vídeo HTML5</a></li><li><a
href="http://lineadecodigo.com/javascript/cambiar-el-valor-de-un-radio-group-dinamicamente/" rel="bookmark" title="Septiembre 19, 2009">Cambiar el valor de un radio group dinámicamente</a></li></ul><p></p> 
<p><a href="http://feedads.g.doubleclick.net/~a/NKKb6yfqxVwU7vJC8YjGRzHENBc/0/da"><img src="http://feedads.g.doubleclick.net/~a/NKKb6yfqxVwU7vJC8YjGRzHENBc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/NKKb6yfqxVwU7vJC8YjGRzHENBc/1/da"><img src="http://feedads.g.doubleclick.net/~a/NKKb6yfqxVwU7vJC8YjGRzHENBc/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Q_J686Pz30s:MX4_dXiZfRA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Q_J686Pz30s:MX4_dXiZfRA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=Q_J686Pz30s:MX4_dXiZfRA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Q_J686Pz30s:MX4_dXiZfRA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?i=Q_J686Pz30s:MX4_dXiZfRA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Q_J686Pz30s:MX4_dXiZfRA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LineaDeCodigo?a=Q_J686Pz30s:MX4_dXiZfRA:tKBiNdHYW3c"><img src="http://feeds.feedburner.com/~ff/LineaDeCodigo?d=tKBiNdHYW3c" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LineaDeCodigo/~4/Q_J686Pz30s" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://lineadecodigo.com/html5/controlar-volumen-de-video-html5-con-un-slider/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <enclosure url="http://easyhtml5video.com/images/happyfit2.ogv" length="10220659" type="video/ogg" /> <feedburner:origLink>http://lineadecodigo.com/html5/controlar-volumen-de-video-html5-con-un-slider/</feedburner:origLink></item> </channel> </rss><!-- Dynamic page generated in 1.829 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-02-22 10:27:38 --><!-- Compression = gzip -->

