<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Nideaderedes &#187; scriptaculous</title>
	<atom:link href="http://nideaderedes.urlansoft.com/tag/scriptaculous/feed/" rel="self" type="application/rss+xml" />
	<link>http://nideaderedes.urlansoft.com</link>
	<description>Un blog hecho por mí y para mí</description>
	<lastBuildDate>Thu, 10 Jun 2010 18:46:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Código para actualizar el contenido de una capa con Scriptaculous</title>
		<link>http://nideaderedes.urlansoft.com/2009/10/21/codigo-para-actualizar-el-contenido-de-una-capa-con-scriptaculous/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/10/21/codigo-para-actualizar-el-contenido-de-una-capa-con-scriptaculous/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 07:00:45 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[scriptaculous]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=954</guid>
		<description><![CDATA[Aquí os dejo un código JavaScript que actualiza el contenido de una capa mediante Ajax. La transición entre el contenido de la capa y el nuevo se hace mediante un efecto de difuminado con Scriptaculous. El efecto se repite cíclicamente.
Usa Protoype y Scriptaculous.
La capa que se actualiza debe llamarse &#8220;capa&#8221;:

&#60;div id=&#34;capa&#34;&#62;&#60;/div&#62;

y en la etiqueta body [...]]]></description>
			<content:encoded><![CDATA[<p>Aquí os dejo un código JavaScript que actualiza el contenido de una capa mediante Ajax. La transición entre el contenido de la capa y el nuevo se hace mediante un efecto de difuminado con Scriptaculous. El efecto se repite cíclicamente.</p>
<p>Usa Protoype y Scriptaculous.</p>
<p>La capa que se actualiza debe llamarse &#8220;capa&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre>&lt;div id=&quot;capa&quot;&gt;&lt;/div&gt;</pre></div></div>

<p>y en la etiqueta body debemos añadir:</p>

<div class="wp_syntax"><div class="code"><pre>&lt;body onload=&quot;start_fading()<SEMI>&quot;&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span>  type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>
<span style="color: #003366; font-weight: bold;">function</span> start_fading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fade<span style="color: #339933;">=</span>setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fadeout()&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> fadeout<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">new</span> Effect.<span style="color: #006600;">Opacity</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;capa&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>duration<span style="color: #339933;">:</span><span style="color: #CC0000;">0.5</span><span style="color: #339933;">,</span> from<span style="color: #339933;">:</span><span style="color: #CC0000;">1.0</span><span style="color: #339933;">,</span> to<span style="color: #339933;">:</span><span style="color: #CC0000;">0.0</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fade<span style="color: #339933;">=</span>setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;change()&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>       
<span style="color: #003366; font-weight: bold;">function</span> change<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #006600;">Request</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/script.php'</span><span style="color: #339933;">,</span>
	  <span style="color: #009900;">&#123;</span>
	    method<span style="color: #339933;">:</span><span style="color: #3366CC;">'get'</span><span style="color: #339933;">,</span>
	    onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>transport<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	      <span style="color: #003366; font-weight: bold;">var</span> response <span style="color: #339933;">=</span> transport.<span style="color: #006600;">responseText</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;no response text&quot;</span><span style="color: #339933;">;</span>
	      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'specials_sidebox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">innerHTML</span> <span style="color: #339933;">=</span> response<span style="color: #339933;">;</span>
		  <span style="color: #003366; font-weight: bold;">new</span> Effect.<span style="color: #006600;">Opacity</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;capa&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>duration<span style="color: #339933;">:</span><span style="color: #CC0000;">0.5</span><span style="color: #339933;">,</span> from<span style="color: #339933;">:</span><span style="color: #CC0000;">0.0</span><span style="color: #339933;">,</span> to<span style="color: #339933;">:</span><span style="color: #CC0000;">1.0</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #003366; font-weight: bold;">var</span> fade<span style="color: #339933;">=</span>setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fadeout()&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	    onFailure<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: #009900;">&#125;</span>
	  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//--&gt;&lt;/script&gt;</span></pre></div></div>

<p>El funcionamiento es el siguiente:</p>
<p>1) El evento onload() de la etiqueta body llama a la función start_fading() que pone en marcha un cronómetro que llamará a la función fadeout() al de 4000 milisegundos.</p>
<p>2) La función fadeout() hace que el elemento &#8220;capa&#8221; vaya desapareciendo difuminándose. Además establece un nuevo cronómetro que llamará al de 600 milisegundos a la función change.</p>
<p>3) La función change hace una llamada al fichero &#8217;script.php&#8217; mediante ajax para cambiar el contenido de capa (que está todavía oculto). Cuando se ha terminado de ejecutar script.php se ejecuta automáticamente la función dentro de &#8216;onSuccess&#8217;.</p>
<p>4) Esta función sustituye el contenido de &#8216;capa&#8217; por lo que haya devuelto script.php, hace un fade in (vuelve a mostrar capa) y establece un nuevo cronómetro para empezar el proceso de nuevo.</p>
<p>NOTAS:</p>
<p>* Hay que tener en cuenta que cada vez que se repite el proceso se hace una llamada a script.php. Si este script consume muchos recursos podemos estar sobrecargando el servidor (cada usuario que tenga la ventana abierta estará haciendo llamadas cada 4600 milisegundos aproximadamente.</p>
<p>* Si es posible quizá fuera mejor precargar los disintos contenidos de &#8216;capa&#8217; e ir rotándolos en cada ciclo sin hacer una llamada Ajax (eso os lo pongo otro día).</p>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/10/21/codigo-para-actualizar-el-contenido-de-una-capa-con-scriptaculous/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
