<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IoSmanetto.it - Blog programmazione e webdesign &#187; jquery</title>
	<atom:link href="http://www.iosmanetto.it/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iosmanetto.it</link>
	<description>Il blog per tutti gli smanettoni del pc. Ogni giorno nuovi articoli sul webdesign e sulla programmazione</description>
	<lastBuildDate>Sat, 16 Apr 2011 16:19:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Personalizzare una Select Box !</title>
		<link>http://www.iosmanetto.it/javascript/personalizzare-un-select-box/</link>
		<comments>http://www.iosmanetto.it/javascript/personalizzare-un-select-box/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 21:26:22 +0000</pubDate>
		<dc:creator>Gregorio</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.iosmanetto.it/?p=511</guid>
		<description><![CDATA[Non tutti i componenti del form sono personalizzabili al 100%, a volte è possibile modificare solo alcune caratteristiche come il colore del testo e dello sfondo . La select box difficilmente viene personalizzata via css perchè molti browser non accettano pienamente questa funzione . Impariamo a creare una select box tutta nostra con l&#8217;ausilio del [...]]]></description>
			<content:encoded><![CDATA[<p><em>Non tutti i componenti del form sono personalizzabili al 100%, a volte è possibile modificare solo alcune caratteristiche come il colore del testo e dello sfondo . </em><br/><br />
La <strong>select box </strong>difficilmente viene personalizzata via css perchè molti browser non accettano pienamente questa funzione .<br />
Impariamo a creare una select box tutta nostra con l&#8217;ausilio del nostro amato framework <strong>Jquery </strong>!</p>
<p>Per l&#8217;occasione ho preparato questo semplice form che è costituito da una textbox , una select box e un submit .</p>
<p><iframe style="border:2px solid black" src="http://www.iosmanetto.it/progetti/javascript/myform/index.html" height=400"></iframe><br />
<span id="more-511"></span><br />
La select box si presenta come un div (.selectBox)  con i segunti nodi figli :</p>
<ol>
<li><strong>.input</strong> Qui viene visualizzato il testo scelto dell&#8217;utente nel menu a tendina</li>
<li><strong>input hidden</strong> Il valore scelto viene copiato in questa field per poter essere inviato durante il submit del form</li>
<li><strong>.arrow</strong> Pulsantino per aprire il menu a tendina</li>
<li><strong>.hoverBox</strong> Una lista (ul) contenente i valori di scelta</li>
</ol>
<p><br/></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;selectbox&quot;&gt;&lt;span class=&quot;&quot;&gt;Seleziona un valore&lt;/span&gt;
    &lt;input type=&quot;hidden&quot; value=&quot;none&quot; name=&quot;field2&quot; /&gt;
    &lt;a href=&quot;#&quot; class=&quot;arrow&quot;&gt;&lt;/a&gt;
    &lt;ul class=&quot;hoverBox&quot;&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;item 1&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;item 2&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;item 3&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;item 4&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;item 5&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;</pre></div></div>

<p>Vediamo cosa fa il seguente codice jquery che regola il funzionamento di tutta la selectbox</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Funzione che viene chiamata quando la pagina si carica</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Gestione freccia Select Box</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.selectbox .arrow&quot;</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>
&nbsp;
<span style="color: #006600; font-style: italic;">// Quando utente clicca sulla freccia ...</span>
&nbsp;
$<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;">parent</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;">&quot;.hoverBox&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>
&nbsp;
&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;">// Quando utente fa click il box scompare</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.selectbox .hoverBox&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseup</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;">hide</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: #006600; font-style: italic;">// Quando utente clicca su un link , il valore viene copiato nello SPAN nell hidden</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.selectbox .hoverBox a&quot;</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: #003366; font-weight: bold;">var</span> value <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;">text</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;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</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;">&quot;input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>value<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;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</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;">&quot;.input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>value<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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Quando l&#8217;utente fa click nella freccia ( .arrow ) viene visualizzato il box contenente i link .</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<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;">parent</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;">&quot;.hoverBox&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></pre></div></div>

<p>Se l&#8217;utente preme un link il valore viene copiato sia nello span , per la visulizzazione grafica , e sia nell&#8217;input hidden .</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<span style="color: #003366; font-weight: bold;">var</span> value <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;">text</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;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</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;">&quot;input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>value<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;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</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;">&quot;.input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.iosmanetto.it/javascript/personalizzare-un-select-box/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Centrare un div al centro della pagina con JQuery/JavaScript</title>
		<link>http://www.iosmanetto.it/javascript/centrare-un-div-al-centro-della-pagina-con-jqueryjavascript/</link>
		<comments>http://www.iosmanetto.it/javascript/centrare-un-div-al-centro-della-pagina-con-jqueryjavascript/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 13:11:02 +0000</pubDate>
		<dc:creator>Gregorio</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[trip & tricks]]></category>

		<guid isPermaLink="false">http://www.iosmanetto.it/?p=375</guid>
		<description><![CDATA[Oggi vi mostrerò come allineare perfettamente un box(div) al centro di una pagina web con l&#8217;ausilio di Jquery, una delle librerie più usate per programmare in javascript. La funzione che ci permette di fare ciò è la seguente : &#60;script type=&#34;text/javascript&#34;&#62; function centerDiv&#40;div&#41;&#123; var DIVwidth = $&#40;div&#41;.width&#40;&#41;; var DIVheight = $&#40;div&#41;.height&#40;&#41;; var SCREENwidth = $&#40;document&#41;.width&#40;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Oggi vi mostrerò come allineare perfettamente un box(div) al centro di una pagina web  con l&#8217;ausilio di Jquery, una delle librerie più usate per programmare in javascript.</p>
<p>La funzione che ci permette di fare ciò è la seguente :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> centerDiv<span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  	<span style="color: #003366; font-weight: bold;">var</span> DIVwidth <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #003366; font-weight: bold;">var</span> DIVheight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> SCREENwidth <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> SCREENheight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #003366; font-weight: bold;">var</span> SCREENscrolltop <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span>div<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>
	$<span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>SCREENwidth<span style="color: #339933;">-</span>DIVwidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;top&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>SCREENheight<span style="color: #339933;">-</span>DIVheight<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #339933;">+</span>SCREENscrolltop<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span>div<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>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">var</span> div <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#boxCenter&quot;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	centerDiv<span style="color: #009900;">&#40;</span>div<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>window<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">scroll</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>
	centerDiv<span style="color: #009900;">&#40;</span>div<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>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">resize</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>
	centerDiv<span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Lo script al primo accesso calcola le coordinate e le imposta al div selezionato . Se l&#8217;utente modifica le dimensioni della finestra vengono calcolate delle nuove coordinate e aggiornate.<br />
<span id="more-375"></span><br />
Proviamo a commentare il cuore del programmino :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	$<span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>SCREENwidth<span style="color: #339933;">-</span>DIVwidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;top&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>SCREENheight<span style="color: #339933;">-</span>DIVheight<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #339933;">+</span>SCREENscrolltop<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>$().css è una funzione JQuery usata per modificare lo stile ( css ) di un elemento html. Ha la seguente sintassi :</p>

<div class="wp_syntax"><div class="code"><pre class="javascrip" style="font-family:monospace;">$(&quot;selettore&quot;).css({&quot;proprietà&quot;:&quot;valore&quot;,&quot;proprietà2&quot;:&quot;valore&quot;,ecec});</pre></div></div>

<p>Le coordinate X del div viene calcolata grazie a questa espressione :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>SCREENwidth<span style="color: #339933;">-</span>DIVwidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span></pre></div></div>

<p>Sottraendo la larghezza del DIV alla larghezza del documento otteniamo i due margini , quello sinistro e destro. Per avere un margine occorre quindi dividere tutto per due .</p>
<p><a href="http://www.iosmanetto.it/wp-content/uploads/2010/01/javascript_marginediv2.jpg"><img class="aligncenter size-full wp-image-384" title="javascript_marginediv" src="http://www.iosmanetto.it/wp-content/uploads/2010/01/javascript_marginediv2.jpg" alt="" width="515" height="333" /></a></p>
<p>Stesso procedimento per la cordinata Y del box , cambia solo un piccolo particolare perché bisogna sommare lo scroll verticale della pagina :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>SCREENheight<span style="color: #339933;">-</span>DIVheight<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #339933;">+</span>SCREENscrolltop</pre></div></div>

<p><a href="http://www.iosmanetto.it/progetti/javascript/JSboxcenter/" target="_blank"><span class="view">Vedi esempio</span></a> &#8211; <a href="http://www.iosmanetto.it/progetti/javascript/JSboxcenter.rar"><span class="download">Scarica</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iosmanetto.it/javascript/centrare-un-div-al-centro-della-pagina-con-jqueryjavascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

