<?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>Gleenk Webdesign</title> <link>http://www.gleenk.com</link> <description>Davide De Maestri - Webdesigner</description> <lastBuildDate>Fri, 03 Feb 2012 19:16:43 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Gleenk-Webdesign" /><feedburner:info uri="gleenk-webdesign" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><image><link>http://www.gleenk.com</link><url>http://www.gleenk.com/wp-content/themes/designpile/images/gl-logo.png</url><title>Gleenk Webdesign</title></image><item><title>Come creare un widget personalizzato per WordPress</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/cms9YSteIis/</link> <comments>http://www.gleenk.com/come-creare-widget-personalizzato-per-wordpress/#comments</comments> <pubDate>Tue, 31 Jan 2012 05:00:05 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[CMS]]></category> <category><![CDATA[Webmaster]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2023</guid> <description><![CDATA[Ecco la struttura per realizzare un widget in wordpress perfettamente funzionante! Vediamola!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2012/01/wordpress-realizzare-widget.jpg" alt="Realizzare un widget con WordPress" title="Realizzare un widget con WordPress" width="620" height="300" class="alignnone size-full wp-image-2035" /><br /> Mentre stiamo realizzando un tema per WordPress, piuttosto che ricorrere a plugin esterni per l&#8217;inserimento di codice PHP (come ad esempio <a href="http://wordpress.org/extend/plugins/php-code-widget/" target="_blank">PHP Code Widget</a>) nelle sidebar, potrebbe tornarci utile realizzare un widget per utilizzare il nostro codice in aree specifiche del sito, senza permettere a terzi (i clienti) di andare a &#8220;toccarlo&#8221; e comprometterne la funzionalità.</p><p>Ci tengo a premettere che non intendo approfondire la tematica  dal punto di vista della programmazione pura, non rientrando nelle mie competenze specifiche, bensì è mio intento indicare un sistema generale e semplice per realizzare un Widget in maniera rapida ed alla portata di tutti, derivato dalla lettura di alcune risorse online e cartacee.</p><h2>Il nostro widget nel file functions</h2><p>Il codice che vediamo va inserito unicamente nel file functions.php del nostro tema. Quello che andremo a fare è realizzare un semplicissimo widget con un titolo, e che stampi una frase. Il nostro widget sarà poi visibile dall&#8217;apposito pannello di WordPress e trascinabile in qualsivoglia <a href="http://codex.wordpress.org/Customizing_Your_Sidebar" target="_blank">sidebar</a>!</p><h3>La struttura funzionale</h3><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php 
<span style="color: #000000; font-weight: bold;">class</span> myWidget <span style="color: #000000; font-weight: bold;">extends</span> WP_Widget <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> myWidget<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: #000000; font-weight: bold;">function</span> widget<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_instance</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$instance</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: #000000; font-weight: bold;">function</span> my_register_widgets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_widget<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'myWidget'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'widgets_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_register_widgets'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>Quella che possiamo vedere qui sopra è la struttura di base che permette al nostro widget di essere riconosciuto e mostrato nel backend di wordpress. Tuttavia così è privo di qualsiasi funzionalità. Sottolineo solo alcuni aspetti che a mio avviso possono interessare. Innanzitutto quello che stiamo andando a fare è estendere la class WP_Widget, ovvero la classe che permette a WP di costruire i widget. In seguito poi abbiamo 4 metodi (funzioni) che permettono di indicare il nome del widget, di eseguirlo realmente, di effettuare correttamente le operazioni di salvataggio e di gestire il campo &#8220;Titolo&#8221; che può essere modificato. Le 4 funzionalità appena elencate fanno riferimento a <code>function myWidget()</code>, <code>function widget()</code>, <code>function update()</code> e <code>function form()</code>.<br /> Infine con la funzione my_register_widgets() (che potete chiamare a vostro piacimento) andiamo a registrare a tutti gli effetti il nostro widget perchè compaia nel backend ed infine lo istanziamo usando <code>add_action()</code>.</p><h3>L&#8217;esempio completo e funzionante</h3><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt; ?php 
class myWidget extends WP_Widget {
	function myWidget() {
		parent::__construct( false, 'Il mio Widget' );
	}
	function widget( $args, $instance ) {
		extract($args);
		echo $before_widget;
		echo $before_title.$instance['title'].$after_title;
&nbsp;
		//DA QUI INIZIA IL WIDGET VERO E PROPRIO
		echo &quot;Ciao Wordpress&quot;;
		//FINE WIDGET
&nbsp;
		echo $after_widget;
	}
	function update( $new_instance, $old_instance ) {
		return $new_instance;
	}
	function form( $instance ) {
		$title = esc_attr($instance['title']); ?&gt;
		&lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
		Titolo: &lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-/&gt;</span>get_field_id<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;&lt; ?php echo $this-&gt;get_field_name('title');?&gt;&quot; type=&quot;text&quot; value=&quot;&lt; ?php echo $title; ?&gt;&quot; /&gt;
		&lt;/label&gt;&lt;/p&gt;
		&lt; ?php
	}
}
&nbsp;
function my_register_widgets() {
	register_widget( 'myWidget' );
}
&nbsp;
add_action( 'widgets_init', 'my_register_widgets' );
?&gt;</pre></div></div><p>Che si mostrerà così nel backend:<br /> <img src="http://www.gleenk.com/wp-content/uploads/2012/01/esempio-my-widget.jpg" alt="" title="Esempio widget di base" width="252" height="129" class="aligncenter size-full wp-image-2028" /></p><p>Come già anticipato non è mia competenza addentrarmi troppo nel mondo della programmazione (in particolare ad oggetti in questo caso) quindi lascio al tuo approfondimento personale lo studio di ciò che avviene in ogni passaggio. Ad ogni modo, con il codice sopra proposto in mano, sarà sufficiente (qualora non intendiate fornire ulteriori opzioni modificabili da backend) scrivere il vostro codice php normalmente al posto di:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//DA QUI INIZIA IL WIDGET VERO E PROPRIO</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Ciao Wordpress&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//FINE WIDGET</span></pre></div></div><p>Potrete infatti inserirei qui tutto ciò che vi pare, ad esempio usando query_post() potreste estrarre alcuni particolari contenuti e così via. Insomma, la struttura funzionale è questa, poi il cuore dovrete farlo pulsare voi <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/paginazione-categorie-personalizzate-wordpress/" rel="bookmark">Paginazione di categorie personalizzate in WordPress</a></li><li><a href="http://www.gleenk.com/prevenire-email-spam-wordpress-con-antispambot/" rel="bookmark">Email di spam in WordPress? Prevenire si può.</a></li><li><a href="http://www.gleenk.com/wordpress-loop-corretto-non-sbagliare/" rel="bookmark">WordPress Loop Snippets &#8211; Partire col piede giusto</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/come-creare-widget-personalizzato-per-wordpress/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://www.gleenk.com/come-creare-widget-personalizzato-per-wordpress/</feedburner:origLink></item> <item><title>Fancybox e Flowplayer, visualizzare i video in popup!</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/tIn0c1iK_jQ/</link> <comments>http://www.gleenk.com/fancybox-e-flowplayer-visualizzare-video-in-popup/#comments</comments> <pubDate>Mon, 23 Jan 2012 05:00:55 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2009</guid> <description><![CDATA[Visualizziamo i nostri video in fantastici popup utilizzando Fancybox e Flowplayer! Che lo spettacolo abbia inizio!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2012/01/testata-fancybox-flowplayer.jpg" alt="Testata Fancybox e Flowplayer" title="Fancybox e Flowplayer: video in Popup!" width="620" height="300" class="alignnone size-full wp-image-2018" /><br /> Recentemente mi sono imbattuto con l&#8217;esigenza di includere un video .flv all&#8217;interno del popup di <a href="http://fancyapps.com/fancybox/" target="_blank">Fancybox</a> (uno script jQuery stile lightbox, con funzionalità più avanzate). Seppur lo script offra già di base il supporto all&#8217;integrazione di video Youtube, non c&#8217;è verso di visualizzare un video, se non utilizzando un iframe nel quale integriamo un lettore esterno.</p><p><a title="Utilizzare Fancybox per visualizzare video" href="http://www.gleenk.com/demo/jquery/fancybox-flowplayer/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><p>Se però abbiamo l&#8217;esigenza di avere il video in pagina &#8220;nascosto&#8221;, siamo costretti a ricorrere ad altri metodi. Ed ecco che, navigando in giro per il web, scopriamo come sia possibile integrare il noto lettore <a href="http://flowplayer.org/" target="_blank">Flowplayer</a> al tanto amato Fancybox. Nel momento in cui scrivo questo articolo garantisco sulla compatibilità totale dei 2 script (in particolare Flowplayer funziona sia con la versione 1.3 che con la versione 2.0+ di Fancybox). L&#8217;unico accorgimento da prendere nel caso si utilizzino versioni di Fancybox differenti, è quello di controllare le funzioni di callback che vengono messe a disposizione.</p><h2>Procuriamoci gli script</h2><p>Per prima cosa, inevitabilmente, scarichiamo Fancybox e Fancyplayer ai link seguenti:<br /> Fancybox: <a href="http://fancyapps.com/fancybox/" target="_blank">http://fancyapps.com/fancybox/</a><br /> Fancyplayer (free): <a href="http://flowplayer.org/download/index.html" target="_blank">http://flowplayer.org/download/index.html</a></p><p>Dopodichè prepariamo la nostra cartella in cui lavoreremo utilizzando la struttura seguente:<br /> <img src="http://www.gleenk.com/wp-content/uploads/2012/01/fancybox-flowplayer-system.jpg" alt="File System Fancybox e Flowplayer" title="Struttura file Fancybox e Flowplayer" width="430" height="130" class="alignnone size-full wp-image-2011" /></p><h2>Prepariamo il codice html da utilizzare</h2><p>Prima di tutto includiamo il css di Fancybox (oltre ad un nostro eventuale foglio stile), jQuery ed i file .js che ci servono:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fancybox/jquery.fancybox.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">link</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fancybox/jquery.fancybox.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flowplayer/flowplayer-3.2.6.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">link</span>&gt;</span></pre></div></div><p>Fatto questo prepariamo la semplicissima struttura html:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;player&quot;</span> data-url<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.gleenk.com/demo/jquery/fancybox-flowplayer/Talbot%20Bay%20-%20Australia%20-%20BBC.flv&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;play-video&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#player&quot;</span>&gt;</span>Play video<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div><p>Come vediamo sarà fondamentale avere un attributo in cui inserire l&#8217;url dove si trova il video: per farlo ci siamo avvalsi della proprieta HTML5 data-<em>nome</em>, dove nome è qualsiasi cosa si voglia. Utilizzando jQuery non avremo alcuna difficoltà ad andare a &#8220;pescare&#8221; questo valore. Vi anticipo fin da subito che non avrete problemi di compatibilità cross-browser.<br /> Inoltre impostiamo l&#8217;href del link con il medesimo nome dell&#8217;ID del contenitore del video.</p><h2>jQuery in azione</h2><p>A questo punto non ci resta che scrivere il codice che realizzerà la magia:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#player&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data-url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a#play-video&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fancybox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		 <span style="color: #3366CC;">'scrolling'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		 <span style="color: #3366CC;">'titleShow'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		 <span style="color: #3366CC;">'padding'</span>  <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
		 <span style="color: #3366CC;">'beforeLoad'</span>  <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;">&#40;</span><span style="color: #3366CC;">&quot;#player&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 $f<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;player&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;flowplayer/flowplayer-3.2.7.swf&quot;</span><span style="color: #339933;">,</span> url<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: #3366CC;">'afterClose'</span>  <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;">&#40;</span><span style="color: #3366CC;">&quot;#player&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 $f<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unload</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></div></div><p>E&#8217; bene sottolineare brevemente alcuni punti. Nel caso che vedete sopra abbiamo utilizzato una variabile url per memorizzare il percorso del video. In questo modo, se avessimo in pagina diversi video, utilizzando opportunamente &#8220;this&#8221; in jQuery potremmo prelevare il video che ci interessa. La variabile url verrebbe infatti cambiata ad ogni click. (Per farlo ricordiamoci di utilizzare delle classi e non ID come nell&#8217;esempio).<br /> Infine è bene precisare che <code>scrolling</code>, <code>titleShow</code>, <code>padding</code> sono proprietà di Fancybox che servono per nascondere spazi, scritte e scrollbar. <code>beforeLoad</code> e <code>afterClose</code> sono invece le 2 callback di cui parlavamo all&#8217;inizio. Sono due funzioni che agiscono prima del caricamento del video e dopo. Saranno queste quelle per cui accertarsi che la sintassi non sia cambiata nel corso di future versioni!</p><h2>Compatibilità con i browser</h2><ul> Il seguente sistema è stato testato e ne è stata accertata la funzionalità sui seguenti browser:</p><li>Mozilla Firefox (qualsiasi versione moderna)</li><li>Chrome (qualsiasi versione moderna)</li><li>Opera (qualsiasi versione moderna)</li><li>Internet Explorer 7+</li></ul><p><a title="Utilizzare Fancybox per visualizzare video" href="http://www.gleenk.com/demo/jquery/fancybox-flowplayer/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/html5-tag-video/" rel="bookmark">HTML5 tag video</a></li><li><a href="http://www.gleenk.com/dollaro-invece-jquery-in-wordpress/" rel="bookmark">Usare ‘$’ invece di ‘jQuery’ in WordPress</a></li><li><a href="http://www.gleenk.com/stilizzare-campi-input-file-jquery/" rel="bookmark">Stilizzare campi input file con jQuery</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/fancybox-e-flowplayer-visualizzare-video-in-popup/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <enclosure url="http://www.gleenk.com/demo/jquery/fancybox-flowplayer/Talbot%20Bay%20-%20Australia%20-%20BBC.flv" length="7665763" type="video/x-flv" /> <feedburner:origLink>http://www.gleenk.com/fancybox-e-flowplayer-visualizzare-video-in-popup/</feedburner:origLink></item> <item><title>Realizzare carte animate con Transizioni e Animazioni CSS3</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/1W9zmBrqFiw/</link> <comments>http://www.gleenk.com/realizzare-carte-animate-con-i-css3/#comments</comments> <pubDate>Tue, 03 Jan 2012 19:25:46 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[css3]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1879</guid> <description><![CDATA[Transizioni e Rotazioni in CSS3! Realizziamo un mazzo di carte che si animano... Solo con i CSS!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2012/01/testata-transizioni-css3.jpg" alt="Testata articolo transizioni e rotazioni css3" title="Transizioni e Rotazioni CSS3" width="620" height="300" class="alignnone size-full wp-image-1987" /><br /> Oggi vediamo come realizzare un set di 3 carte utilizzando esclusivamente i CSS3! Niente jQuery questa volta! Andremo a sfruttare in particolar modo le <a href="http://www.w3schools.com/cssref/css3_pr_rotation.asp" target="_blank">proprietà di rotazione</a> e le <a href="http://css3.bradshawenterprises.com/" target="_blank">transizioni</a>.</p><p><a title="esempio di transizione e rotazione css3" href="http://www.gleenk.com/demo/css/transizioni-carte-css3/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><h2>Nel DOM solo Ul e Li</h2><p>La struttura HTML di cui ci serviamo presenta semplicemente un lista disordinato in cui, ad ogni <code>li</code> andiamo ad assegnare un ID unico affinchè possiamo interagire con la proprietà CSS3 di rotazione in modo diversificato:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;carte&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clearfix&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;carta-1&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Carta 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque dapibus ante et lectus convallis consectetur. Maecenas quis turpis tellus, sit amet aliquam urna. Sed nec suscipit metus. Pellentesque dignissim commodo lectus, id vulputate neque hendrerit vel. Nulla dictum bibendum eros id accumsan. Aenean ut purus nulla. Integer faucibus volutpat odio sit amet ornare. Nunc orci metus, euismod nec vehicula sed, aliquam sed turpis. Vivamus eget ultrices neque. Sed viverra egestas tristique. Fusce tincidunt vulputate urna et commodo. Curabitur feugiat semper eros quis rhoncus. Duis orci mauris, pretium sed accumsan id, ornare non ligula. <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;carta-2&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Carta 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Quisque rutrum lacus et nunc porta in congue nunc sagittis. Phasellus et mauris at elit condimentum bibendum. In nisi magna, imperdiet rhoncus egestas non, aliquam id justo. Sed vel elit est, id dictum ipsum. Integer ultricies sagittis lorem non semper. Maecenas sit amet imperdiet odio. Vestibulum tempus, metus a aliquam tincidunt, justo arcu elementum nunc, eget commodo ante sapien ac odio. Morbi cursus, nisl ac rhoncus sollicitudin, erat velit placerat elit, nec commodo lorem dolor sed elit. Praesent rutrum, est ut blandit pulvinar, tortor elit eleifend nulla, vel vulputate libero felis eget ligula.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;carta-3&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Carta 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Morbi eu massa sit amet turpis dignissim porta. Phasellus eget justo quis augue fermentum consectetur. Cras ac nunc quis nunc bibendum rhoncus. Ut aliquam, risus id pharetra sagittis, neque tellus aliquam risus, nec condimentum nunc neque a urna. Nam ut magna vel est suscipit cursus. Cras a rutrum nibh. Suspendisse id nisl magna, eu tincidunt nulla. Nullam adipiscing, sem et euismod iaculis, felis orci mollis risus, nec viverra turpis velit ut elit. Vestibulum a eros vel nunc ullamcorper mattis.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div><h2>CSS3, rotazioni ed animazioni</h2><p>Di per sè il codice che utilizziamo non è complesso, è semplicemente un po&#8217; lungo da scrivere, soprattutto a causa dei numerosi prefissi che siamo costretti ad usare per cercare di ampliare un minimo il bacino di utenti che potranno osservare il nostro capolavoro <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ! Vi riporto il codice CSS per intero, poi analizziamo i punti più interessanti. Se volete fare a meno dei prefissi potete avventurarvi nella sperimentazione di <a href="http://leaverou.github.com/prefixfree/" target="_blank">prefixfree</a>, uno script che farà il lavoro sporco per noi!</p><div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#container</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">760px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Verdana</span><span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#carte</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#carte</span> li <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">450px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	-moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #933;">2px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #933;">2px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #933;">2px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	-moz-transition<span style="color: #00AA00;">:</span> all 0.5s ease-in-out<span style="color: #00AA00;">;</span>
	-webkit-transition<span style="color: #00AA00;">:</span> all 0.5s ease-in-out<span style="color: #00AA00;">;</span>
	transition<span style="color: #00AA00;">:</span> all 0.5s ease-in-out<span style="color: #00AA00;">;</span>
	-moz-<span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	-webkit-<span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#carta-1</span> <span style="color: #00AA00;">&#123;</span>
	-webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-20deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-20deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-ms-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-20deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-20deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#carta-2</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">70px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#carta-3</span> <span style="color: #00AA00;">&#123;</span>
	-webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>20deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>20deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-ms-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-20deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>20deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">3</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#carte</span> li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">4</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f90</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span>
	-moz-<span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">0px</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	-webkit-<span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">0px</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">0px</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#carta-1</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
	-moz-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-18deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-webkit-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-18deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-ms-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-18deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> 
	transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-18deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#carta-2</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
	-moz-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-webkit-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-ms-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> 
	transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> 
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#carta-3</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
	-moz-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>18deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-webkit-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>18deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> 
	-ms-transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>-18deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> 
	transform<span style="color: #00AA00;">:</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.1</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span>18deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div><p>Tralasciamo box-shadow, bordi e smancierie puramente estetiche. Quello che fondamentalmente ci interessa sono le proprietà transition e transform.<br /> In particolare utilizzando <code><strong>transition: all 0.5s ease-in-out</strong></code> diciamo al browser che, nel momento in cui inizia la nostra azione, deve avvenire una transizione di tutte le proprietà (all) da uno stato all&#8217;altro (solitamente hover) in 0.5 secondi utilizzando una determinata curva (ease-in-out).</p><p>Con la proprietà <code><strong>transform: scale(1.1) rotate(18deg);</strong></code> invece definiamo una trasformazione dell&#8217;oggetto rispetto alla posizione originale. In particolare ne alteriamo le dimensioni (scale) e lo ruotiamo di tot gradi (rotate).<br /> La combinazione delle due proprietà permette il passaggio graduale come mostrato nell&#8217;esempio. Relativamente semplice no?<br /> <a title="esempio di transizione e rotazione css3" href="http://www.gleenk.com/demo/css/transizioni-carte-css3/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/css3-per-internet-explorer-6-7-8/" rel="bookmark">CSS3 per Internet Explorer 6-7-8+</a></li><li><a href="http://www.gleenk.com/la-pseudo-classe-target-css3/" rel="bookmark">Lo pseudo selettore :target | CSS3</a></li><li><a href="http://www.gleenk.com/border-radius-css3-come-arrotondare-i-bordi/" rel="bookmark">Border Radius CSS3 &#8211; Come arrotondare i bordi</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/realizzare-carte-animate-con-i-css3/feed/</wfw:commentRss> <slash:comments>5</slash:comments> <feedburner:origLink>http://www.gleenk.com/realizzare-carte-animate-con-i-css3/</feedburner:origLink></item> <item><title>Paginatore in jQuery: come realizzarlo sfruttando le liste non ordinate</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/ptWPznzaB5I/</link> <comments>http://www.gleenk.com/paginatore-jquery-usando-liste-non-ordinate/#comments</comments> <pubDate>Sat, 17 Dec 2011 05:00:11 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1970</guid> <description><![CDATA[Realizziamo un paginatore in jQuery utilizzando le liste non ordinate, vediamo passo passo come fare!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2011/12/paginatore-jquery-liste-non-ordinate.jpg" alt="Paginatore jQuery utilizzando le liste html" title="paginatore-jquery-liste-non-ordinate" width="620" height="300" class="alignnone size-full wp-image-1972" /><br /> In questo articolo, scritto dall&#8217;amministratore di <a href="http://www.qmpeople.com">qmpeople.com</a>, egli sottopone  alla vostra attenzione un paginatore jQuery  molto semplice e costituito nientaltro che da una lista di risultati da visualizzare opportunamente marcata con id di classe che permettono a jQuery di definirne la formattazione.</p><h2>Liste non ordinate intelligenti</h2><p>Tutti gli sviluppatori conoscono bene le liste non ordinate in quanto permettono di raggruppare logicamente un insieme di elementi creando di fatto un contenuto semantico molto apprezzato anche dai motori di ricerca.</p><p>jQuery come noto ci permette di lavorare agevolmente anche con questo tipo di strutture dati arricchendole di eventi o modificandone il layout.</p><h3>Liste + jQuery: una possibile modalità di utilizzo</h3><p>Tutto normale fin qui ma la cosa intelligente sta nel fatto che tutte le informazioni utili alla visualizzazione dei singoli item sono cablate direttamente negli attributi della lista! Per chiarire meglio questo aspetto analizziamo passo passo il relativo codice sorgente partendo proprio dalla lista di elementi.</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;p_current_page&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span>hidden&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;p_show_per_page&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span>hidden&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;p_total_pages type=hidden&quot;</span>&gt;</span></pre></div></div><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;topnumbers&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pt&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">h3</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;t-numbers&quot;</span>&gt;</span>Numeri da 1 a 10<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;uno.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>uno<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;due.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>due<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tre.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>tre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;quattro.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>quattro<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cinque.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>cinque<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sei.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>sei<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sette.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>sette<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;otto.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>otto<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nove.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>nove<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dieci.jpg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;number_li&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>dieci<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pn&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;next();return false;&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Next<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div><p>I primi tre campi nascosti servono rispettivamente per memorizzare il numero di pagina corrente del paginatore, il numero di righe del paginatore ed il numero totale di pagine da cui è costituito</p><p>Come anticipato, nell&#8217;attributo &#8220;name&#8221; dei link contenuti nei singoli singoli item della lista è stato inserito il nome del file che verrà utilizzato da jQuery per visualizzare accanto al testo cliccabile una immagine personalizzata. Questo stratagemma risulta particolarmente utile in quanto ci permette di risparmiare costose connessioni http che avremmo dovuto realizzare qualora si volesse recuperare le medesime informazioni in modo dinamico</p><p>Riguardo la parte CSS non c&#8217;è molto da segnalare eccezion fatta per la diversa formattazione imposta al primo e all&#8217;ultimo elemento della lista in quanto rispettivamente header e footer della stessa.</p><h3>Passiamo quindi all&#8217;analisi del codice jQuery</h3><p>La prima cosa che viene fatta al caricamento della pagina consiste nell&#8217;inizializzare i tre campi nascosti per poi richiamare la funzione go_to_page_numbers con paramentro 0 ad indicare che ci si posizionerà nella pagina iniziale del paginatore</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<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: #003366; font-weight: bold;">var</span> show_per_page<span style="color: #339933;">=</span><span style="color: #CC0000;">4</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> number_of_items<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#topnumbers'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.number_li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#p_current_page'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#p_show_per_page'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>show_per_page<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#p_total_pages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">ceil</span><span style="color: #009900;">&#40;</span>number_of_items<span style="color: #339933;">/</span>show_per_page<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
go_to_page_numbers<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</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></pre></div></div><p>La funzione che segue viene richiamata dal link di paginazione e non fa altro che calcolare il numero di pagina a cui si vuole accedere a partire da quella corrente memorizzata nel campo nascosto #p_current_page per poi passarlo alla funzione go_to_page_numbers</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> next<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
new_page<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#p_current_page'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#p_total_pages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#p_current_page'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #CC0000;">0</span><span style="color: #339933;">;</span>
go_to_page_numbers<span style="color: #009900;">&#40;</span>new_page<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Vediamo dunque come funziona il cuore del paginatore ossia la funzione go_to_page_numbers</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> go_to_page_numbers<span style="color: #009900;">&#40;</span>page_num<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>page_num<span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> show_per_page<span style="color: #339933;">=</span>parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#p_show_per_page'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> show_per_page<span style="color: #339933;">=</span>parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#p_show_per_page'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>page_num<span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> start_from<span style="color: #339933;">=</span>page_num <span style="color: #339933;">*</span> show_per_page<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>
<span style="color: #003366; font-weight: bold;">var</span> start_from<span style="color: #339933;">=</span>page_num <span style="color: #339933;">*</span> show_per_page<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">var</span> end_on<span style="color: #339933;">=</span>start_from <span style="color: #339933;">+</span> show_per_page<span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#topnumbers'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;li&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'none'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span>start_from<span style="color: #339933;">,</span> end_on<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#pt,#pn'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#topnumbers'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.number_li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> n<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;table cellpadding=0 cellspacing=0&gt;&lt;tr&gt;&lt;td&gt;&lt;img class=b width=45 height=45 alt=&quot;'</span> <span style="color: #339933;">+</span> n <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; title=&quot;'</span> <span style="color: #339933;">+</span> n <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; style=vertical-align:middle src='</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/-/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&gt;&lt;/td&gt;&lt;td&gt;'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;a class=&quot;number_li&quot; href=&quot;#&quot;&gt;'</span> <span style="color: #339933;">+</span> n <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/a&gt;'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/span&gt;'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;'</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: #009900;">&#40;</span><span style="color: #3366CC;">'#p_current_page'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>page_num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>I primi due blocchi if else servono per impostare correttamente il numero di righe da visualizzare in virtù del fatto che scorrendo le varie pagine potrebbe cambiare il numero di elementi</p><p>Grazie ai metodi children e slice vengono modificati tutti gli elementi della lista aggiungendovi l&#8217;istruzione css <code>display:none</code> che li rende tutti invisibili. (ad eccezione del primo e dell&#8217;ultimo)</p><p>Subito dopo utilizzando i metodi children, slice ed each prima e replaceWith nell&#8217;istruzione successiva, vengono individuati, selezionati e quindi modificati tutti e soli quegli elementi della lista la cui posizione è compresa tra i valori start_from ed end_on in modo tale che al posto dell&#8217;item nascosto <code>&lt;li&gt;</code> venga visualizzata una tabella di due colonne che andrà a comporre la struttura desiderata di ogni singola riga del paginatore.</p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/rotazione-automatica-di-immagini-con-jquery/" rel="bookmark">Rotazione automatica immagini con jQuery</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/paginatore-jquery-usando-liste-non-ordinate/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://www.gleenk.com/paginatore-jquery-usando-liste-non-ordinate/</feedburner:origLink></item> <item><title>Cambiare un’immagine di sfondo casualmente con jQuery</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/vGJhRUHcSgI/</link> <comments>http://www.gleenk.com/immagine-di-sfondo-casuale-con-jquery/#comments</comments> <pubDate>Tue, 06 Dec 2011 05:00:20 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1946</guid> <description><![CDATA[Realizziamo uno script client-side per impostare immagini casuali ad ogni caricamento di pagina!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2011/12/testata-immagini-multiple.jpg" alt="Testata tutorial immagini a rotazione casuale in javascript" title="Realizziamo un&#039;immagine che cambia continuamente!" width="620" height="300" class="alignnone size-full wp-image-1951" /><br /> Può capitare. durante la nostra vita lavorativa da webdesigner quotidiana o i momenti di svago, di incappare nella necessità di realizzare uno sfondo che cambi dinamicamente, ma di non aver, per esempio, possibilità e/o le competenze per utilizzare un linguaggio server side come php.<br /> Vediamo quindo come, con poche righe di codice, è possibile ottenere il risultato sperato! Saranno sufficienti un minimo di competenze di javascript ed un&#8217;accortezza nella nomenclatura delle foto che utilizzeremo.</p><p><a title="esempio di rotazione casuale di immagini con jQuery" href="http://www.gleenk.com/demo/jquery/rotazione-casuale-immagini-javascript/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><h2>Il nostro script in poche righe</h2><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<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>
    totaleImmagini<span style="color: #339933;">=</span><span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
    randomNumber <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>totaleImmagini<span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    imgPath<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/my/image/path/'</span><span style="color: #339933;">+</span>randomNumber<span style="color: #339933;">+</span><span style="color: #3366CC;">'.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//il percorso può essere relativo o assoluto</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-image'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'url(&quot;'</span><span style="color: #339933;">+</span>imgPath<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;)'</span><span style="color: #009900;">&#41;</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></pre></div></div><p>Spiego a parole quello che fa lo script. In primo luogo dichiariamo il numero di immagini che abbiamo a disposizione da far ruotare. Nel nostro caso saranno 5. Successivamente, utilizzando le funzione <a href="http://www.w3schools.com/jsref/jsref_round.asp" target="_blank">Math.round</a> (arrotonda al numero intero più vicino) e <a href="http://www.w3schools.com/jsref/jsref_random.asp" target="_blank">Math.random</a> (genera un numero casuale tra 0 e 1), estraiamo un numero casuale compreso tra 1 e 5. Dichiariamo quindi il percorso in cui si trovano le nostre immagini ed impostiamo, ad esempio, lo sfondo del nostro contenitore con l&#8217;immagine scelta. Ne va da sè che ad ogni aggiornamento della pagina la foto cambierà.</p><h3>Attenzione alla nomenclatura</h3><p>Nell&#8217;esempio appena visto, affinchè lo script funzioni, è necessario che le nostre immagini siano numerate da 1 a 5. Nel caso avessimo la necessità di dare dei nomi più sensati alle foto, dovranno comunque mantenere una struttura nel nome simile. Ad esempio, se stiamo utilizzando delle foto di cascate, potremo scrivere cascate-niagara-01.jpg ecc&#8230; andando quindi a cambiare il percorso (path) dell&#8217;immagine in: <code>imgPath=('/my/image/path/cascate-niagara-0'+randomNumber+'.jpg');</code></p><p><a title="esempio di rotazione casuale di immagini con jQuery" href="http://www.gleenk.com/demo/jquery/rotazione-casuale-immagini-javascript/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/estrazione-numeri-casuali-compresi-tra-due-valori-jquery-javascript/" rel="bookmark">Estrazione di numeri casuali compresi tra due valori in jQuery/Javascript</a></li><li><a href="http://www.gleenk.com/cookie-e-jquery-cambiamo-foglio-stile/" rel="bookmark">jQuery cookie per ambiare foglio stile!</a></li><li><a href="http://www.gleenk.com/rotazione-automatica-di-immagini-con-jquery/" rel="bookmark">Rotazione automatica immagini con jQuery</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/immagine-di-sfondo-casuale-con-jquery/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://www.gleenk.com/immagine-di-sfondo-casuale-con-jquery/</feedburner:origLink></item> <item><title>Animazioni jQuery con effetti Easing</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/hDJHcAH_y0k/</link> <comments>http://www.gleenk.com/jquery-animate-con-effetti-easing/#comments</comments> <pubDate>Mon, 21 Nov 2011 05:00:02 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1915</guid> <description><![CDATA[Vuoi dare un tocco di dinamismo alle tue animazioni con jQuery? Utilizziamo l'effetto easing!]]></description> <content:encoded><![CDATA[<p>Easing, ovvero &#8220;attenuare, allentare&#8221;. Diciamo subito che forse la traduzione del termine è poso esemplificativa, ad ogni modo gli effetti di easing sono quella serie di rimbalzi, frenate, accelerazioni ecc. che alterano l&#8217;andamento lineare di un movimento. Nel nostro caso in particolare, sono tutti quegli effetti che permetteranno alle animazioni jQuery di essere più dinamiche e d&#8217;impatto.</p><p><a title="esempio di animazioni con effetti di easing in jQuery" href="http://www.gleenk.com/demo/jquery/effetti-easing" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><h2>jQuery easing:il plugin</h2><p>E&#8217; nato prima l&#8217;uovo o la gallina? In questo caso non saprei rispondere, nel senso che non mi è dato di sapere se sia nato prima questo plugin e poi la nota libreria <a href="http://docs.jquery.com/UI/Effects" title="jQuery UI effetti di Easing" target="_blank">jQuery UI</a>, o se sia stata la seconda ad inglobare il plugin originale. Fatto sta che possiamo avere a disposizione questa serie di effetti senza per forza portarci dietro tutto il pacchetto UI. Quindi in primis procuriamoci il <a href="http://gsgd.co.uk/sandbox/jquery/easing/" target="_blank">plugin che ci servirà dal sito ufficiale</a>.</p><p>A questo punto, includiamo jQuery nella nostra pagina Html ed andiamo a scrivere il nostro amato codice&#8230;</p><p><strong>Premessa doverosa:</strong> <em>gli effetti di easing si possono applicare solo alla funzione <a title="jQuery animate function" href="http://api.jquery.com/animate/" target="_blank">animate()</a></em>! Quindi ogni tentativo di utilizzo differente non funzionerà! Per intenderci, non possiamo applicarli alle funzioni show() o hide().</p><h2>Html e css</h2><p>Poco da dire a riguardo, l&#8217;unica accortezza è quella, affinchè l&#8217;esempio funzioni, di impostare una <code>position:relative</code> o <code>absolute</code> al contenitore da spostare, altrimenti la proprietà left non funziona!</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;esempio-easing&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;easBounce&quot;</span>&gt;</span>Effetto di rimbalzo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;esempio-easing&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;easElastic&quot;</span>&gt;</span>Effetto elastico<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;esempio-easing&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;easOutBack&quot;</span>&gt;</span>Effetto frenata e rimbalzo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div><div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.esempio-easing</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FC0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span></pre></div></div><h2>Animare con gli effetti: jQuery</h2><p>Tolte le premesse veniamo al succo della questione. In realtà quello che dovremo fare è molto semplice, ci basterà scrivere la funzione animate correttamente, per questo vi rimando alla documentazione ufficiale, e sostituire l&#8217;effetto di easing di default con quelli di nostro interesse. In particolare nell&#8217;esempio sottostante vediamo 3 tipi di animazioni:</p><ul><li>Effetto di rimbalzo</li><li>Effetto elastico</li><li>Effetto frenata e rimbalzo</li></ul><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<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: #006600; font-style: italic;">//EFFETTO DI RIMBALZO</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#easBounce'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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;">&quot;.complete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			left<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span>
		  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'easeOutBounce'</span><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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				left<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'easeOutBounce'</span><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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;complete&quot;&gt;Animazione completata.&lt;/div&gt;'</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: #009900;">&#125;</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: #006600; font-style: italic;">//EFFETTO ELASTICO</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#easElastic'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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;">&quot;.complete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			left<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span>
		  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'easeOutElastic'</span><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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				left<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'easeOutElastic'</span><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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;complete&quot;&gt;Animazione completata.&lt;/div&gt;'</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: #009900;">&#125;</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: #006600; font-style: italic;">//EFFETTO FRENATA E RIMBAZO</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#easOutBack'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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;">&quot;.complete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			left<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span>
		  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'easeOutBack'</span><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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				left<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'easeOutBack'</span><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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;complete&quot;&gt;Animazione completata.&lt;/div&gt;'</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: #009900;">&#125;</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: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p><a title="esempio di animazioni con effetti di easing in jQuery" href="http://www.gleenk.com/demo/jquery/effetti-easing" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><p>In questo modo sfruttiamo la funzione animate a &#8220;cascata&#8221; ed eseguiamo in callback l&#8217;azione di ritorno al punto di origine annidandola dentro alla funzione animate principale. Per chi fosse interessato è possibile realizzare effetti a catena utilizzando invece i deferred object di jQuery. A tal proposito vi linko un <a href="http://gabrieleromanato.com/2011/10/jquery-gestire-la-catena-di-animazioni-con-i-deferred-objects/" target="_blank">interessante articolo di Gabriele Romanato</a>. Buona lettura e buona sperimentazione!</p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/effetto-easing-su-menu-con-jquery-ui/" rel="bookmark">Effetto Easing su menù con jQuery UI</a></li><li><a href="http://www.gleenk.com/votazione-con-jquery-animate/" rel="bookmark">Votazione con jQuery animate</a></li><li><a href="http://www.gleenk.com/ruotare-scalare-oggetti-jquery-2d-transform/" rel="bookmark">Ruotare e scalare oggetti con jQuery 2D transform</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/jquery-animate-con-effetti-easing/feed/</wfw:commentRss> <slash:comments>4</slash:comments> <feedburner:origLink>http://www.gleenk.com/jquery-animate-con-effetti-easing/</feedburner:origLink></item> <item><title>jQuery per far scorrere le ultime news in 4 righe!</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/hI-vEGUZbCY/</link> <comments>http://www.gleenk.com/jquery-scorrimento-news/#comments</comments> <pubDate>Sun, 13 Nov 2011 22:55:44 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1830</guid> <description><![CDATA[Realizziamo un semplice sistema di scorrimento di news utilizzando 4 righe di codice jQuery, vediamo come fare!]]></description> <content:encoded><![CDATA[<p>Esistono molti plugins che permettono di realizzare dei &#8220;news ticker&#8221;, ovvero script che permettono di vedere le ultime <strong>news scorrere</strong>.<br /> Oggi vediamo però come realizzare la nostra versione semplificata <strong>utilizzando solamente 4 righe di codice</strong>.</p><p>L&#8217;idea di base è molto semplice, prendiamo il primo elemento di una lista, lo facciamo sparire e, in callback, lo riaggiungiamo alla fine della lista.</p><p><a title="esempio di news-ticker in jQuery" href="http://www.gleenk.com/demo/jquery/news-ticker" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><h2>Il codice HTML da utilizzare</h2><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ticker&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ticker&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Lorem ipsum dolor sit amet<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>, luctus et ultrices consectetur adipiscing elit. Praesent condimentum sagittis risus ac viverra. Integer vestibulum volutpat...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam at ligula purus. Fusce ligula massa, commodo eu aliquam non, pharetra ut nisl.... <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Proin mollis eros quis massa dictum sodales. Suspendisse elementum, dui sed tincidunt ultricies, dolor ipsum dictum felis, id consequat ligula risus...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Sed<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> liquam eget blandit elit. Aenean luctus et ultrices arcu augue, fringilla a eleifend in, bibendum sed augue. Aliquam consectetur arcu at arcu...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div><p>Come possiamo vedere non c&#8217;è nulla di strano, solo un semplice elenco puntato dal quale andremo a nascondere il primo elemento&#8230;</p><h2>Il CSS e due regole, il resto è creatività!</h2><p>Affinchè lo nostro script funzioni correttamente sarà bene prendere alcune accortezze. Il mio consiglio spassionato è quello di <strong>impostare un&#8217;altezza fissa</strong> agli elementi di lista ed al contenitore, all&#8217;&lt;ul&gt; quindi, per evitare che l&#8217;altezza del blocco in cui è inserito il nostro widget vari continuamente creando uno sgradevole effetto visivo. Nel mio caso, tralasciando la non-creatività <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , mi sono limitato ad impostare quanto appena esposto:</p><div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#ticker</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">243px</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#ticker</span> li <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#ticker</span> li a <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F90</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span></pre></div></div><p>La dichiarazione overflow:hidden viene messa solo a scopo precauzionale nel caso in cui ci si dimenticasse si troncare il testo alla lunghezza desiderata. In questo modo non straborderà fuori dal contenitore ma verrà nascosto.</p><h2>Azioniamo il tutto con jQuery</h2><p>Bastano infine 4 righe per far partire l&#8217;animazione desiderata&#8230; vediamo che cosa scrivere:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> ticker<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;">'#ticker li:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</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: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ticker'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</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: #009900;">&#125;</span>
setInterval<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> ticker <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>La funzione ticker() viene lanciata grazie al <a href="http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/" target="_blank">setInterval()</a> che ci dice di ripetere le azioni ogni 3000 ms (3 secondi). Lo script dice invece semplicemente di effettuare lo <a href="http://api.jquery.com/slideUp/" target="_blank">slideUp()</a> del primo elemento della lista, di appenderlo in coda a #ticker e quindi di fare lo <a href="http://api.jquery.com/slideDown/" target="_blank">slideDown()</a>.<br /> Ed il trucco è presto svelato <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p><a title="esempio di news-ticker in jQuery" href="http://www.gleenk.com/demo/jquery/news-ticker" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/liste-sequenziali-elementi-consecutivi-indici/" rel="bookmark">Liste sequenziali ed elementi consecutivi con jQuery</a></li><li><a href="http://www.gleenk.com/accordion-jquery/" rel="bookmark">Realizzare un accordion jQuery in 5 righe di codice!</a></li><li><a href="http://www.gleenk.com/jquery-news-spot-slider/" rel="bookmark">jQuery News Slider &#8211; gleenk spotSlider v1.0</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/jquery-scorrimento-news/feed/</wfw:commentRss> <slash:comments>5</slash:comments> <feedburner:origLink>http://www.gleenk.com/jquery-scorrimento-news/</feedburner:origLink></item> <item><title>Consigli per ottimizzare le immagini per i motori di ricerca</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/fCfm9SwzJmg/</link> <comments>http://www.gleenk.com/consigli-per-ottimizzare-le-immagini-per-i-motori-di-ricerca/#comments</comments> <pubDate>Mon, 07 Nov 2011 18:19:28 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[SEO - SEM - COPY]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1850</guid> <description><![CDATA[Ottimizzare le immagini per il web, piccoli consigli e good-practise da seguire.]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2011/11/ottimizzare-immagini-consigli.jpg" alt="ottimizzare immagini consigli" title="Come ottimizzare le immagini per i motori di ricerca?" width="620" height="300" class="alignnone size-full wp-image-1855" /><br /> Solitamente le immagini ottimizzate per il web appaiono nei motori di ricerca, nei siti di sharing come <a href="http://www.flickr.com" target="_blank">Flickr</a>, e sui siti di condivisione immagini (come <a href="http://imageshack.us/" target="_blank">imageshack</a>). La ricerca per immagini è sempre in crescita ed attualmente consta più di 360.000 ricerche mensili su Google, Yahoo ecc&#8230; Questo è il motivo per cui tutti i proprietari di siti web non dovrebbero ignorare il processo di ottimizzazione. Vediamo quindi alcuni passaggi da tenere sempre in considerazione.</p><h2>Qualità prima di tutto</h2><p>Le immagini che utilizzi dovranno rispettare gli standard di qualità. Parametri come la risoluzione, il contrasto saranno fondamentali perchè catturino l&#8217;attenzione fin dalle piccole thumbs che si vedranno nei risultati di ricerca. E&#8217; un dato di fatto che gli utenti siano maggiormente attratti da immagini dettagliate, questo è il buon motivo per prestarci attenzione. Il peso tuttavia non è secondario alla qualità, assicurati quindi, se utilizzi ad esempio Photohop, di salvare sempre l&#8217;immagine per il web cercando il miglior compromesso possibile tra qualità e peso.</p><h2>Utilizza il formato corretto</h2><p>E&#8217; sempre meglio ricordare che le immagini vanno salvate in .jpeg laddove possibile mentre il .png è consigliato per loghi, bottoni e laddove si riveli indispensabile l&#8217;utilizzo del canale alfa per le trasparenze. Sebbene non siano regole &#8220;ferree&#8221;, nel processo di ottimizzazione è bene seguire dei canoni possibilmente precisi.</p><p>I nomi dei files sono importanti. Questo è un fattore che viene spesso trascurato per lasciare spazio ai poco utili &#8220;DSC8457.jpg&#8221; o &#8220;01.jpg&#8221;. Assicurati invce sempre che il nome sia rilevante e coincida esattamente con ciò che si vede. Inoltre non usare gli spazi, ma fai uso dei trattini (-) per separare le parole. Quando ottimizzi immagini per il web infine verifica sempre che il file robots.txt non blocchi l&#8217;accesso alla cartella dove tieni salvati i files!</p><h2>Aggiornamento e fattori tecnici: l&#8217;attributo ALT</h2><p>Se le tue immagini sono il target ottimale per parole chiave molto popolari, potrebbe essere una buona pratica quella di ri-caricarle di tanto in tanto. Mantenerle aggiornate potrebbe risultare un fattore importante per il loro posizionamento.</p><p>L&#8217;<a href="http://www.webhouseit.com/wiki/attributo-alt/" target="_blank">attributo ALT</a> in HTML è utilizzato per specificare un testo alternativo da mostrare quando l&#8217;immagine non può essere renderizzata. Devi fare in modo che questo tag sia sempre presente e descriva fedelmente ciò che si vede nell&#8217;immagine, possibilmente contenente le parole chiave presenti anche nel nome del files. E&#8217; ciò che infatti consente al motore di interpretare l&#8217;immagine, così come ad un lettore vocale.</p><p>Tutto questo però potrebbe non bastare da solo, infatti è fondamentale che il testo che circonda le immagini sia coerente con quanto rappresentato e contestualizzi l&#8217;illustrazione con il contenuto della pagina.</p><h2>Limita il numero e il peso delle immagini</h2><p>Dato che le immagini sono ciò che fa aumentare maggiormente il peso delle tue pagine web è bene che esse occupino sempre il minor spazio possibile. Quando possibile cerca di stare dentro i 30Kb per immagine ed utilizza gli sprites CSS per tutte quelle simil-immagini (loghi, pulsanti, bottoni di share&#8230;) per ridurre le chiamate al server.</p><p>Per farlo utilizza alcune risorse gratuite online per ottimizzare le immagini comprimendole o creando gli sprites:</p><ul><li><a href="http://www.smushit.com/ysmush.it/" target="_blank">Smushit</a></li><li><a href="http://punypng.com/" target="_blank">PunyPNG</a></li><li><a href="http://www.cssspritesgenerator.it" target="_blank">Css Sprites Generator</a></li></ul><p><span style="font-size:9px; font-style:italic">Tratto e rivisto da: <a href="http://designmodo.com/optimize-images-search-engines/">&#8220;How to Optimize Images for Search Engines&#8221;</a></span></p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/5-consigli-importanti-per-il-seo/" rel="bookmark">5 Consigli importanti per il SEO</a></li><li><a href="http://www.gleenk.com/consigli-per-un-copy-user-e-seo-friendly/" rel="bookmark">Consigli per scrivere un copy User e SEO Friendly</a></li><li><a href="http://www.gleenk.com/aggiungere-dimensioni-immagini-diversi-post-wordpress/" rel="bookmark">Set di dimensioni di immagini diverse per i nostri articoli WordPress</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/consigli-per-ottimizzare-le-immagini-per-i-motori-di-ricerca/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://www.gleenk.com/consigli-per-ottimizzare-le-immagini-per-i-motori-di-ricerca/</feedburner:origLink></item> <item><title>Select tagliate in IE7? Un piccolo script per risolvere</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/Ha9lF8_mjSg/</link> <comments>http://www.gleenk.com/select-tagliate-in-ie7-un-piccolo-script-per-risolvere/#comments</comments> <pubDate>Tue, 01 Nov 2011 15:27:28 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1841</guid> <description><![CDATA[Internet Explorer 7 taglia le voci della tua select senza pietà? Usiamo questo piccolo script per risolvere definitivamente il problema!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2011/11/selectproblem.png" alt="Problema delle select tagliate in IE 6 e 7" title="Browser e finti browser, ecco che cosa succede..." width="570" height="387" class="alignnone size-full wp-image-1845" /></p><p>Ecco, quello che vedi nella foto è ciò che accade esattamente quando si cerca di dare una <strong>dimensione fissa ad una select</strong>. Purtroppo quelli che, a mio avviso, non possono più considerarsi &#8220;browser&#8221; come li pensiamo noi, tagliano brutalmente i contenuti delle tendine senza alcuna pietà.</p><p>Se per IE6 l&#8217;unica strada percorribile è quella di utilizzare script che &#8220;trasformano&#8221; la select in un div (ma vi assicuro che potreste uscirne davvero pazzi), per IE7 <strong>è stato realizzato uno script</strong> da Craig Hoover (reso pubblico su <a href="http://css-tricks.com/snippets/jquery/fix-select-dropdown-cutoff-in-ie-7/" target="_blank">css-tricks.com</a>)che, inserito rigorosamente prima della chiusura del &lt;body&gt;, e come ultimo script, permette di ottenere anche su IE7 lo stesso tipo di renderizzazione grafica che si ha per le <strong>opzioni delle select</strong> nei browser moderni.</p><p><a title="Demo fix problema tendine IE7" href="http://jsbin.com/aceqo6/6" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a><br /> (da visualizzare con Internet Explorer 7)</p><h2>jQuery per risolvere&#8230;</h2><p>Vi riporto quindi, così come è stato pubblicato, il codice da incollare affinchè questo odioso problema si risolva.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Safely use $</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>
&nbsp;
        $.<span style="color: #660066;">fn</span>._ie_select<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> 
&nbsp;
                <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</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> 
&nbsp;
                        <span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                            p <span style="color: #339933;">=</span> a.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        p.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'position'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'relative'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        <span style="color: #003366; font-weight: bold;">var</span> o <span style="color: #339933;">=</span> a.<span style="color: #660066;">position</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                            h <span style="color: #339933;">=</span> a.<span style="color: #660066;">outerHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                            l <span style="color: #339933;">=</span> o.<span style="color: #660066;">left</span><span style="color: #339933;">,</span>
                            t <span style="color: #339933;">=</span> o.<span style="color: #660066;">top</span><span style="color: #339933;">;</span>
&nbsp;
                        <span style="color: #003366; font-weight: bold;">var</span> c <span style="color: #339933;">=</span> a.<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        $.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span>c<span style="color: #339933;">,</span><span style="color: #3366CC;">'element'</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        c.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                                zIndex   <span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
                                height   <span style="color: #339933;">:</span> h<span style="color: #339933;">,</span>
                                top      <span style="color: #339933;">:</span> t<span style="color: #339933;">,</span>
                                left     <span style="color: #339933;">:</span> l<span style="color: #339933;">,</span>
                                position <span style="color: #339933;">:</span> <span style="color: #3366CC;">'absolute'</span><span style="color: #339933;">,</span>
                                width    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'auto'</span><span style="color: #339933;">,</span>
                                opacity  <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                                id    <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'-clone'</span><span style="color: #339933;">,</span>
                                <span style="color: #000066;">name</span>  <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'-clone'</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</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: #660066;">data</span><span style="color: #009900;">&#40;</span>c<span style="color: #339933;">,</span><span style="color: #3366CC;">'element'</span><span style="color: #009900;">&#41;</span>
                                        .<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                                        .<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'change'</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        a.<span style="color: #660066;">before</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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>
                                c.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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>
&nbsp;
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// END RETURN</span>
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// END PLUGIN</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Usage</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">msie</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'select'</span><span style="color: #009900;">&#41;</span>._ie_select<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// END SAFETY</span></pre></div></div><p>Da notare come in chiusura di script venga effettuata la verifica del browser affinchè lo script venga eseguito solo sui browser microsoft.<br /> Se invece si volesse eseguire lo script unicamente se viene riconosciuta la versione 7 di Explorer, è possibile sostituire con:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> isIE7 <span style="color: #339933;">=</span> $.<span style="color: #660066;">browser</span>.<span style="color: #660066;">msie</span> <span style="color: #339933;">&amp;&amp;</span> parseFloat<span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">version</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">7</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isIE7<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'select'</span><span style="color: #009900;">&#41;</span>._ie_select<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>E tu che tecnica utilizzi di solito?</p><p><span style="font-size:10px; font-style:italic">Immagini e fonte dello script: <a href="http://css-tricks.com/" target="_blank">css-tricks.com</a></span></p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/5-semplici-trucchi-per-risolvere-problemi-seo/" rel="bookmark">5 semplici trucchi per risolvere grandi problemi SEO</a></li><li><a href="http://www.gleenk.com/didascalie-immagini-jquery-hover-animate/" rel="bookmark">Didascalie per immagini con jQuery hover e animate</a></li><li><a href="http://www.gleenk.com/simulare-fonte-di-luce-dinamica-in-javascript/" rel="bookmark">Simulare una fonte di luce dinamica in JavaScript</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/select-tagliate-in-ie7-un-piccolo-script-per-risolvere/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.gleenk.com/select-tagliate-in-ie7-un-piccolo-script-per-risolvere/</feedburner:origLink></item> <item><title>WordPress Loop Snippets – Partire col piede giusto</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/fNf4P3xXdvo/</link> <comments>http://www.gleenk.com/wordpress-loop-corretto-non-sbagliare/#comments</comments> <pubDate>Mon, 24 Oct 2011 18:36:44 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[CMS]]></category> <category><![CDATA[wordpress]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1832</guid> <description><![CDATA[Due snippet del Loop di Wordpress da copiare ed incollare al volo in fase di creazione dei propri templates personalizzati!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2011/10/wordpress-loop-cheatsheet.jpg" alt="Testata articolo WordPress loop Snippets" title="Wordpress loop cheatsheet" width="620" height="300" class="alignnone size-full wp-image-1836" /><br /> Quelli che trovate di seguito sono degli snippets pronti da copiare e incollare dentro ai templates di wordpress per partire a sviluppare il proprio sito nel modo corretto! Il <a href="http://codex.wordpress.org/The_Loop" target="_blank">Loop</a> è infatti semplicemente il cuore di WordPress, la parte più importante da capire ed è quindi importante avere pronta una risorsa da sfruttare all&#8217;inizio di ogni progetto!</p><h2>Il loop semplice &#8220;condensato&#8221;</h2><p>Questa è la versione immediata e funzionale del Loop. Nessun fronzolo o personalizzazione.Verrà infatti mostrato solo il contenuto!</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;</span> ?php the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Leggi tutto »'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #666666; font-style: italic;">//Qui può essere messo ciò che si vuole che appaia nel caso in cui non si trovino post</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><h2>Il loop completo, pronto per la pagina di un blog</h2><p>Questo esempio è un po&#8217; più complesso. Include molti tag di &#8220;core&#8221; di WordPress che solitamente vengono usati per realizzare un blog d&#8217;informazione. Ma è solamente un incipit, sicuramente non esaustivo:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post-&lt;!--?php the_ID(); ?--&gt;&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;!--?php the_permalink() ?--&gt;&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bookmark&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Link a &lt; ?php the_title(); ?&gt;&quot;</span><span style="color: #339933;">&gt;&lt;</span> ?php the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>h2<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>small<span style="color: #339933;">&gt;&lt;</span> ?php the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'F jS, Y'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #339933;">&lt;!--</span> by <span style="color: #339933;">&lt;!--</span>?php the_author<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> ?<span style="color: #339933;">--&gt;</span> <span style="color: #339933;">--&gt;&lt;/</span>small<span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;entry&quot;</span><span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span> ?php the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Leggi tutto »'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;postmetadata&quot;</span><span style="color: #339933;">&gt;</span>Scritto in <span style="color: #339933;">&lt;!--</span>?php the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span> ?<span style="color: #339933;">--&gt;</span> <span style="color: #339933;">&lt;</span>strong<span style="color: #339933;">&gt;|&lt;/</span>strong<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span> ?php edit_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Edit'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;strong&gt;|'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #339933;">&lt;</span> ?php comments_popup_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Nessun commento »'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1 Commento »'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'% Commenti
		»'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;navigation&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;alignleft&quot;</span><span style="color: #339933;">&gt;&lt;</span> ?php next_posts_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'« Articoli precedenti'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;alignright&quot;</span><span style="color: #339933;">&gt;&lt;</span> ?php previous_posts_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Articoli recenti »'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;</span>h2 <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #339933;">&gt;</span>Non trovato<span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #339933;">&gt;</span>Spiacenti<span style="color: #339933;">,</span> ma stai cercando qualcosa che non si trova qui<span style="color: #339933;">.&lt;/</span>p<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">include</span> <span style="color: #009900;">&#40;</span>TEMPLATEPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/searchform.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>Una piccola nota&#8230; La parte finale in cui si include il file searchform.php senza utilizzare direttamente la funzione <a href="http://codex.wordpress.org/Function_Reference/get_search_form" target="_blank">get_search_form()</a> permette di gestire form multiple nella stessa pagina! Dimenticavo&#8230; Se avete dubbi, chiedete <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p><span style="font-size:10px">Liberamente tratto da <a href="http://wp.tutsplus.com/articles/cheat-sheets/wordpress-cheat-sheat/">&#8220;WordPress Cheat Sheet&#8221;</a></span></p><div class="clear"></div><div class="post-correlati"><h4>Altri articoli che potrebbero interessarti</h4><ol><li><a href="http://www.gleenk.com/wordpress-templates-differenti-articoli/" rel="bookmark">Templates differenti per articoli diversi in WordPress</a></li><li><a href="http://www.gleenk.com/paginazione-categorie-personalizzate-wordpress/" rel="bookmark">Paginazione di categorie personalizzate in WordPress</a></li><li><a href="http://www.gleenk.com/trasferire-wordpress-in-un-nuovo-dominio/" rel="bookmark">Trasferire WordPress 2.9 in un nuovo dominio</a></li></ol><div class="feedSub"><a href="http://feeds.feedburner.com/Gleenk-Webdesign" rel="nofollow"><img src="http://www.gleenk.com/wp-content/themes/designpile/images/rss2_7-01.png" alt="Webdesign Feed Rss" /></a></div></div> ]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/wordpress-loop-corretto-non-sbagliare/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://www.gleenk.com/wordpress-loop-corretto-non-sbagliare/</feedburner:origLink></item> </channel> </rss>

