<?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>Zen-Dreams [dot] com &#187; jQuery</title>
	<atom:link href="http://blog.zen-dreams.com/blog-en/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zen-dreams.com/blog-en</link>
	<description>Blog&#039;s Archives</description>
	<lastBuildDate>Fri, 20 Aug 2010 07:25:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating a popup window with jQuery</title>
		<link>http://blog.zen-dreams.com/blog-en/2009/06/09/creating-a-popup-window-with-jquery/</link>
		<comments>http://blog.zen-dreams.com/blog-en/2009/06/09/creating-a-popup-window-with-jquery/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 18:25:01 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Information Technologies]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Visual Effects]]></category>

		<guid isPermaLink="false">http://blog.zen-dreams.com/en/?p=602</guid>
		<description><![CDATA[I think it&#8217;s time for me to go back in more programming language posts rather than focusing only on WordPress. So here is the first post I&#8217;ll make on the fabulous jQuery engine. The goal of this small tutorial will be to show you how to create popping windows in only a few lines of [...]]]></description>
			<content:encoded><![CDATA[<p>I think it&#8217;s time for me to go back in more <strong>programming language</strong> posts rather than focusing only on <strong>WordPress</strong>. So here is the first post I&#8217;ll make on the fabulous <strong><a href="http://blog.zen-dreams.com/en/tag/jquery/">jQuery</a> </strong>engine.</p>
<p>The goal of this small tutorial will be to show you how to create popping windows in only a few lines of code.</p>
<h2>First, the demo</h2>
<p>// </p>
<p><!-- #popup { height: 100%; width: 100%; background: #000000; position: absolute; top: 0; left: 0; -moz-opacity:0.75; -khtml-opacity: 0.75; opacity: 0.75; filter:alpha(opacity=75); z-index: 99; } #window { width: 600px; height: 300px; margin: 0 auto; border: 1px solid #000000; background: #ffffff; position: absolute; top: 200px; z-index: 100; left: 25%; } --></p>
<p><a href="Show_Popup();">Show popup</a></p>
<div>
<div><a href="Close_Popup();">Close</a></p>
<h2>This is the content test for this demo</h2>
</div>
</div>
<h2>1. Setup your environment</h2>
<p>First, you have to grab the latest version of <a href="http://jquery.com/" target="_blank">jQuery on their site</a>.<span id="more-602"></span></p>
<p>Unzip it where you are going to use it and just add to your site&#8217;s header these lines in the &lt;head&gt; element :<br />
<code>&lt;script src="js/jquery.js" type="text/javascript"&gt;&lt;/script&gt;</code></p>
<p>Once you have done that, you must create within your page the placeholder for your content, to do that, just add these lines just before the &lt;/body&gt; in your code.</p>
<p><code>&lt;div id="popup" style="display: none;"&gt;&lt;/div&gt;<br />
&lt;div id="window" style="display: none;"&gt;<br />
&lt;div id="popup_content"&gt;&lt;a href="#" onclick="Close_Popup();"&gt;Close&lt;/a&gt; &lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p>These lines will create two divs not nested so that you can get <strong>transparency </strong>on the Popup layer and not on the Window Layer. If you put Window inside the Popup div, you will see that transparency will be <span style="text-decoration: underline">inherited</span> and that&#8217;s not what we want here.</p>
<h2>2. The css</h2>
<p>In this part we will define the way we want to display windows, you can use nested css or simply put them in a separate file.<br />
<code><br />
#popup {<br />
height: 100%;<br />
width: 100%;<br />
background: #000000;<br />
position: absolute;<br />
top: 0;<br />
-moz-opacity:0.75;<br />
-khtml-opacity: 0.75;<br />
opacity: 0.75;<br />
filter:alpha(opacity=75);<br />
}</code></p>
<p>#window {<br />
width: 600px;<br />
height: 300px;<br />
margin: 0 auto;<br />
border: 1px solid #000000;<br />
background: #ffffff;<br />
position: absolute;<br />
top: 200px;<br />
left: 25%;<br />
}</p>
<p>You will note that there are 4 lines to handle transparency, this is for compatibility purpose until all the browsers support the opacity property. If you don&#8217;t really care about IE, you can skip the filter line.</p>
<p><strong>So what do we have here ?</strong></p>
<p>We have a black background with 75% opacity that takes the whole page (if you don&#8217;t care about IE, I would suggest changing the <em>position: absolute;</em> to <em>position: fixed;</em>. Why ? So that it never whos any white space when scrolling down to the page.</p>
<p>Second definition is just to position the window itself.</p>
<p>Here what it looks like :<img class="aligncenter size-full wp-image-604" src="http://blog.zen-dreams.com/wp-content/uploads/2009/06/popup.png" alt="popup" width="500" height="306" /></p>
<h2>3. The jQuery code for the effects</h2>
<p>Once you have prepared the html and css, you must have your popup ready to be displayed.</p>
<p>Usually, what I do is put some Ajax request in there but I won&#8217;t go into that today, But we are still going to create one function to dislpay the popup and one to close it. Just after the divs you created, add these lines :<br />
<code><br />
&lt;script type="text/javascript"&gt;<br />
function Show_Popup(action, userid) {<br />
$('#popup').fadeIn('fast');<br />
$('#window').fadeIn('fast');<br />
}<br />
function Close_Popup() {<br />
$('#popup').fadeOut('fast');<br />
$('#window').fadeOut('fast');<br />
}<br />
&lt;/script&gt;</code></p>
<p>And that&#8217;s it, you are nearly finished, now all you have to do is trigger these function when you click somewhere (maybe using a onClick=&#8221;Show_Popup()&#8221; event)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zen-dreams.com/blog-en/2009/06/09/creating-a-popup-window-with-jquery/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

