<?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>Tutorials Archive &#187; Javascript</title>
	<atom:link href="http://tutarchive.com/category/web-design-development/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://tutarchive.com</link>
	<description>Save and Share your Tutorials</description>
	<lastBuildDate>Thu, 04 Feb 2010 02:51:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>15+ jQuery Popup Modal Dialog Plugins and Tutorials</title>
		<link>http://tutarchive.com/2009/09/15-jquery-popup-modal-dialog-plugins-and-tutorials/</link>
		<comments>http://tutarchive.com/2009/09/15-jquery-popup-modal-dialog-plugins-and-tutorials/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 01:12:51 +0000</pubDate>
		<dc:creator>TutArchive</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Modal Dialog]]></category>
		<category><![CDATA[Popup]]></category>

		<guid isPermaLink="false">http://tutarchive.com/?p=250</guid>
		<description><![CDATA[
jQuery Popup Modal Dialog Windows

Modal dialog windows are a great way to show quick information to your users, but to also alert them of errors, warnings, prompts for information and more.  When you bring jQuery into the mix, you know you’re going to end up with a slick dialog that really makes the application or [...]


Related posts:<ol><li><a href='http://tutarchive.com/2009/09/jquery-lightbox/' rel='bookmark' title='Permanent Link: jQuery Lightbox'>jQuery Lightbox</a></li><li><a href='http://tutarchive.com/2009/09/turn-off-windows-security-center-alert-taskbar-popup/' rel='bookmark' title='Permanent Link: Turn Off Windows Security Center Alert Taskbar Popup'>Turn Off Windows Security Center Alert Taskbar Popup</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div id="attachment_1179" style="width: 300px;">
<p>jQuery Popup Modal Dialog Windows</p></div>
<p style="text-align: center;"><img class="alignright" title="jQuery Popup Modal Dialog Windows" src="http://choosedaily.com/wp-content/uploads/2009/09/jquery-dialog.jpg" alt="jQuery Popup Modal Dialog Windows" width="290" height="171" /></p>
<p>Modal dialog windows are a great way to show quick information to your users, but to also alert them of errors, warnings, prompts for information and more.  When you bring jQuery into the mix, you know you’re going to end up with a slick dialog that really makes the application or website come alive.  The following is a list of 15+ jQuery Popup Modal Dialog Plugins and Tutorials.</p>
<p><span style="background-color: #ffffff;"><em>There are a couple towards the bottom that you’ll want to pay attention to.  On one the original is in Italian, but I’ve included a link to an English translation.  The other is more on a backend, but I’ve included a link to the zip file for downloading the files.</em></span></p>
<p><span style="background-color: #ffffff;">Let the fun begin!  If you know of any that are missing but should be included, drop a comment!</span></p>
<p><strong><a href="http://dev.iceburg.net/jquery/jqModal/">jqModal</a></strong><br />
qModal is a plugin for jQuery to help you display notices, dialogs, and modal windows in a web browser. It is flexible and tiny, akin to a “Swiss Army Knife”, and makes a great base as a general purpose windowing framework.</p>
<p><span id="more-250"></span></p>
<p><strong><a href="http://nyromodal.nyrodev.com/">NyroModal</a></strong><br />
Modal popup windows provide a quick way to show data without reloading the entire page. One of the big problems with jQuery Popup Modal Dialog window plugins is the customization. This plugin tries to solve those problems. The default CSS contains only optional rules. Without it, the plugin will works perfectly —but will also looks very sad. Regarding the animations, you can simply redefine them from A to Z.</p>
<p><strong><a href="http://www.queness.com/post/77/simple-jquery-modal-window-tutorial">Simple jQuery Modal Window Tutorial</a></strong><br />
In this tutorial, I’m going to share how to create a simple modal window with jQuery. It selects all the anchor tags with name attribute set to “modal” and grab the DIV #id defined in the href and displays it as a modal window. jQuery has made everything so simple, be sure to check out the demonstrations, examples I made.</p>
<p><strong><a href="http://jqueryui.com/demos/dialog/">jQuery UI Dialog</a></strong><br />
The jQuery UI framework offers up a functional Dialog widget that allows resizing and also the ability to display forms. The basic dialog window is an overlay positioned within the viewport and is protected from page content (like select elements) shining through with an iframe. It has a title bar and a content area, and can be moved, resized and closed with the ‘x’ icon by default.</p>
<p><strong><a href="http://www.ericmmartin.com/projects/simplemodal/">SimpleModal</a></strong><br />
SimpleModal is a lightweight jQuery Plugin which provides a powerful interface for modal dialog development. Think of it as a modal dialog framework. SimpleModal gives you the flexibility to build whatever you can envision, while shielding you from related cross-browser issues inherent with UI development.</p>
<p><strong><a href="http://onehackoranother.com/projects/jquery/boxy/">Boxy</a></strong><br />
Boxy is a flexible, Facebook-style dialog box for jQuery with support for dragging and size tweening. It differs from other overlays I’ve seen by providing an object interface to control dialogs after they’ve been created. And for simple usage scenarios, boxy also provides a jQuery plugin for automatically hooking up links and forms, as well as an ask() helper for presenting multiple choices to the user.</p>
<p><strong><a href="http://jquery.com/demo/thickbox/">ThickBox</a></strong><br />
ThickBox is a webpage UI dialog widget written in JavaScript on top of the jQuery library. Its function is to show a single image, multiple images, inline content, iframed content, or content served through AJAX in a hybrid modal.</p>
<p><strong><a href="http://malsup.com/jquery/block/#overview">jQuery BlockUI Plugin</a></strong><br />
The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. When activated, it will prevent user activity with the page (or part of the page) until it is deactivated. BlockUI adds elements to the DOM to give it both the appearance and behavior of blocking user interaction.</p>
<p><strong><a href="http://trentrichardson.com/Impromptu/index.php">jQuery Impromptu</a></strong><br />
jQuery Impromptu is an extension to help provide a more pleasant way to spontaneously prompt a user for input. More or less this is a great replacement for an alert, prompt, and confirm. Not only does it replace these but it also allows for creating forms within these controls. This is not intended to be a modal replacement, just a quick tool to prompt user input in a fashionable way.</p>
<p><strong><a href="http://abeautifulsite.net/notebook/87">jQuery Alert Dialogs (Alert, Confirm &amp; Prompt Replacements)</a></strong><br />
This jQuery plugin aims to replace the basic functionality provided by the standard JavaScript alert(), confirm(), and prompt() functions. What’s the benefit of using custom methods? These are completely customizable via CSS. You can set a custom title for each dialog. IE7 users get an ugly warning and usually have to reload the page if you use a regular prompt(). These methods simulate a true modal dialog box. They will automatically re-position themselves if you resize the browser window (unlike many existing dialog/lightbox-style plugins). If you include the jQuery UI Draggable plugin, the dialogs can be moved by dragging their title bars.</p>
<p><strong><a href="http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/">How to Create a Stunning and Smooth Popup Using jQuery</a></strong><br />
Nowadays, websites are more and more rich and interactive and users are becoming more and more critical with all things in websites. Using windows popup to show important information are in the air and We are going to learn how to create a stunning and great window popup from the scratch using jQuery in a simple and clean tutorial.</p>
<p><strong><a href="http://jorenrapini.com/blog/css/jquery-validation-contact-form-with-modal-slide-in-transition">jQuery Ajax Validation Contact Form with Modal + Slide-in Transition</a></strong><br />
Due to popular demand, here is a tutorial on how I created one of the more complicated pieces of machinery on my new site: the contact form. All you need is jQuery. No plugins are necessary for this to work, and it is only 2kb of extra code in addition to the jQuery library. This also works on all browsers, IE6 and up.</p>
<p><strong><a href="http://www.bitrepository.com/exit-modal-box.html">Creating an Exit Modal Box using jQuery</a></strong><br />
Do you need to show a specific message to the visitors that leave your website? You can do that by initiating a modal box before they close the browser window. To do this we need to include 2 JQuery files (the actual library and a plugin written by Eric Martin), the modal box’s CSS and the file that triggers the modal box based on the user’s action.</p>
<p><strong><a href="http://www.web-development-blog.com/archives/upload-in-modal-window-and-pass-values-with-jquery/">Upload in Modal Window and Pass Values with jQuery</a></strong><br />
Do you publish your blogs with Wordpress? If yes, you know the inline popup window which opens if you like to upload / insert an image into your article. This tutorial shows you how-to use the jQuery Plugin ThickBox and some jQuery code to upload a file and pass a value to the parent page. You can use this kind of feature in your custom CMS or maybe you like use it as a basic for your own file upload plugin or gadget?</p>
<p><strong><a href="http://www.sitespotting.it/esempi/002/">jQuery Modal Choose Component</a></strong><br />
This original article is written in Italian, but here is the <a href="http://translate.google.com/translate?hl=en&amp;sl=it&amp;tl=en&amp;u=http://www.sitespotting.it/esempi/002/">translated English version</a>. I wanted to be sure and include this in the rundown because it gives another option on how to allow users to choose values for a form field. It’s designed as an alternative to the combo box, or select dropdown menu. It’s not perfect, but it’s an interesting take on a common UI component and I believe deserves to be on the list.</p>
<p><strong><a href="http://tautologistics.com/projects/jquery.modaldialog/doc/1.0.0/">jQuery Modal Dialog Plugin</a></strong><br />
This plugin link goes to the working example and documenation page that shows off some real nice jQuery modal dialogs for errors, warnings, prompts and more. Getting to the download is a little tricky unless you <a href="http://tautologistics.com/projects/jquery.modaldialog/src/jquery.modaldialog.1.0.0.zip">follow this link to download</a>.</p>
<p><strong><a href="http://colorpowered.com/colorbox/">ColorBox</a></strong><br />
ColorBox is a lightweight, customizable lightbox plugin that simulates some things that you would like to accomplish with a jQuery popup modal dialog window. It can allow you to show popup ajax, inline and iframed content as well as photos and other media. It’s writting in jQuery plugin format and can be chained with other jQuery commands.</p>
<div style="display: none;">VN:F [1.6.5_908]</div>


<p>Related posts:<ol><li><a href='http://tutarchive.com/2009/09/jquery-lightbox/' rel='bookmark' title='Permanent Link: jQuery Lightbox'>jQuery Lightbox</a></li><li><a href='http://tutarchive.com/2009/09/turn-off-windows-security-center-alert-taskbar-popup/' rel='bookmark' title='Permanent Link: Turn Off Windows Security Center Alert Taskbar Popup'>Turn Off Windows Security Center Alert Taskbar Popup</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://tutarchive.com/2009/09/15-jquery-popup-modal-dialog-plugins-and-tutorials/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Object Oriented Programming with JavaScript : Timer Class</title>
		<link>http://tutarchive.com/2009/09/object-oriented-programming-with-javascript-timer-class/</link>
		<comments>http://tutarchive.com/2009/09/object-oriented-programming-with-javascript-timer-class/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 02:06:23 +0000</pubDate>
		<dc:creator>TutArchive</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://tutarchive.com/?p=222</guid>
		<description><![CDATA[JavaScript with Oops is not much used by developers while creating application however we can make our life easy if we use JavaScript with Oops.
Let's started object oriented programming in JavaScript by taking example of a Timer class, similar to the Timer control in windows application.
Create Class
Create the class Timer. Below code shows how to [...]


Related posts:<ol><li><a href='http://tutarchive.com/2009/09/flex-alert-listen-to-the-buttons/' rel='bookmark' title='Permanent Link: Flex Alert! Listen to the buttons'>Flex Alert! Listen to the buttons</a></li><li><a href='http://tutarchive.com/2009/09/checking-username-availability-with-mootools-and-request-json/' rel='bookmark' title='Permanent Link: Checking Username Availability with Mootools and Request.JSON'>Checking Username Availability with Mootools and Request.JSON</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>JavaScript with Oops is not much used by developers while creating application however we can make our life easy if we use JavaScript with Oops.</p>
<p>Let's started object oriented programming in JavaScript by taking example of a Timer class, similar to the Timer control in windows application.<br />
<strong>Create Class</strong></p>
<p>Create the class Timer. Below code shows how to declare the class</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Declaring class &quot;Timer&quot;</span>
<span style="color: #003366; font-weight: bold;">var</span> Timer <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: #006600; font-style: italic;">// ....</span>
    <span style="color: #006600; font-style: italic;">// Class body</span>
    <span style="color: #006600; font-style: italic;">// ....</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-222"></span><br />
<strong>Add Public Properties</strong></p>
<p>To add public properties to the class we use this keyword as shown below</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Declaring class &quot;Timer&quot;</span>
<span style="color: #003366; font-weight: bold;">var</span> Timer <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: #006600; font-style: italic;">// Property: Frequency of elapse event of the timer in millisecond</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Interval</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Property: Whether the timer is enable or not</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Enable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can see that we have created 2 properties (Interval and Enable) of Timer class and assigned default values to them.<br />
<strong>Add Events (If any)</strong></p>
<p>Now we might want to add events to the class in case we need. For Timer class we need "Tick" event which will be fired every after "Interval". Event are added the same way as the public properties.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Declaring class &quot;Timer&quot;</span>
<span style="color: #003366; font-weight: bold;">var</span> Timer <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: #006600; font-style: italic;">// Property: Frequency of elapse event of the timer in millisecond</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Interval</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Property: Whether the timer is enable or not</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Enable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Event: Timer tick</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Tick</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Add Private Member Variables</strong><br />
We need 2 private variable in the class to hold the timer Id and the class instance. The private variable are added using 'var' keyword.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Declaring class &quot;Timer&quot;</span>
<span style="color: #003366; font-weight: bold;">var</span> Timer <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: #006600; font-style: italic;">// Property: Frequency of elapse event of the timer in millisecond</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Interval</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Property: Whether the timer is enable or not</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Enable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Event: Timer tick</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Tick</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Member variable: Hold interval id of the timer</span>
    <span style="color: #003366; font-weight: bold;">var</span> timerId <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Member variable: Hold instance of this class</span>
    <span style="color: #003366; font-weight: bold;">var</span> thisObject<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Add Functions</strong><br />
Public functions are also added the same way as public properties using this keyword. We need 2 function in the timer, first "Start" to start the timer and second "Stop" to stop the timer.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Declaring class &quot;Timer&quot;</span>
<span style="color: #003366; font-weight: bold;">var</span> Timer <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: #006600; font-style: italic;">// Property: Frequency of elapse event of the timer in millisecond</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Interval</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Property: Whether the timer is enable or not</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Enable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Event: Timer tick</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Tick</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Member variable: Hold interval id of the timer</span>
    <span style="color: #003366; font-weight: bold;">var</span> timerId <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Member variable: Hold instance of this class</span>
    <span style="color: #003366; font-weight: bold;">var</span> thisObject<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Function: Start the timer</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Start</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Enable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Boolean<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;
        thisObject <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>thisObject.<span style="color: #660066;">Enable</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            thisObject.<span style="color: #660066;">timerId</span> <span style="color: #339933;">=</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>
                thisObject.<span style="color: #660066;">Tick</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: #339933;">,</span> thisObject.<span style="color: #660066;">Interval</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: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Function: Stops the timer</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">Stop</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>
        thisObject.<span style="color: #660066;">Enable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        clearInterval<span style="color: #009900;">&#40;</span>thisObject.<span style="color: #660066;">timerId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can see I have incorporated the timer functionality using the setInterval function of the JavaScript. Our class is ready for use now.</p>
<p><strong>Using the Class</strong><br />
To use the class first create the instance of Timer.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now assign the value to its properties as needed.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">obj.<span style="color: #660066;">Interval</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">;</span></pre></div></div>

<p>Attach handler to the events</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">obj.<span style="color: #660066;">Tick</span> <span style="color: #339933;">=</span> timer_tick<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> timer_tick<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;">// Do something..</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now call the "Start" function to start the timer</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">obj.<span style="color: #660066;">Start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To stop the timer anytime in between just call the "Stop" function.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">obj.<span style="color: #000066;">Stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="padding-left: 30px; text-align: right;">Source: <a href="http://www.dailycoding.com/Posts/object_oriented_programming_with_javascript__timer_class.aspx" target="_blank">Dailycoding</a></p>


<p>Related posts:<ol><li><a href='http://tutarchive.com/2009/09/flex-alert-listen-to-the-buttons/' rel='bookmark' title='Permanent Link: Flex Alert! Listen to the buttons'>Flex Alert! Listen to the buttons</a></li><li><a href='http://tutarchive.com/2009/09/checking-username-availability-with-mootools-and-request-json/' rel='bookmark' title='Permanent Link: Checking Username Availability with Mootools and Request.JSON'>Checking Username Availability with Mootools and Request.JSON</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://tutarchive.com/2009/09/object-oriented-programming-with-javascript-timer-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using RegEx (Regular Expressions) in JavaScript</title>
		<link>http://tutarchive.com/2009/09/using-regex-regular-expressions-in-javascript/</link>
		<comments>http://tutarchive.com/2009/09/using-regex-regular-expressions-in-javascript/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 01:56:52 +0000</pubDate>
		<dc:creator>TutArchive</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://tutarchive.com/?p=219</guid>
		<description><![CDATA[Javascript has built-in support for regular expression in almost all browsers. This means you can use regular expression at client side too. You can use to validate the user's input data at client side itself to reduce the server side processing, however you may want to check those at server side too for security problems.
To [...]


Related posts:<ol><li><a href='http://tutarchive.com/2009/09/15-php-regular-expressions-for-web-developers/' rel='bookmark' title='Permanent Link: 15 PHP regular expressions for web developers'>15 PHP regular expressions for web developers</a></li><li><a href='http://tutarchive.com/2009/09/object-oriented-programming-with-javascript-timer-class/' rel='bookmark' title='Permanent Link: Object Oriented Programming with JavaScript : Timer Class'>Object Oriented Programming with JavaScript : Timer Class</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Javascript has built-in support for regular expression in almost all browsers. This means you can use regular expression at client side too. You can use to validate the user's input data at client side itself to reduce the server side processing, however you may want to check those at server side too for security problems.</p>
<p>To use regular expression in javascript you can use the RegExp object</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myRegExp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;[a-zA-z]+&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Or you can directly creates its instance by using special syntax</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myRegExp <span style="color: #339933;">=</span> <span style="color: #339933;">/</span><span style="color: #009900;">&#91;</span>a<span style="color: #339933;">-</span>zA<span style="color: #339933;">-</span>z<span style="color: #009900;">&#93;</span><span style="color: #339933;">+/</span></pre></div></div>

<p><span id="more-219"></span><br />
To test a string against a RegExp</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myRegExp <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/[a-zA-z]+/</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>myRegExp.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dailycoding&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Success</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: #006600; font-style: italic;">// Fail</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you want to extract multiple matched from the input string</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myRegExp <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/[a-zA-z]+/</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> inputString <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;www.dailycoding.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> myMatches <span style="color: #339933;">=</span> document.<span style="color: #660066;">frm1</span>.<span style="color: #660066;">txt1</span>.<span style="color: #660066;">value</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span>myRegExp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>myMatches.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myMatches<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>



<p>Related posts:<ol><li><a href='http://tutarchive.com/2009/09/15-php-regular-expressions-for-web-developers/' rel='bookmark' title='Permanent Link: 15 PHP regular expressions for web developers'>15 PHP regular expressions for web developers</a></li><li><a href='http://tutarchive.com/2009/09/object-oriented-programming-with-javascript-timer-class/' rel='bookmark' title='Permanent Link: Object Oriented Programming with JavaScript : Timer Class'>Object Oriented Programming with JavaScript : Timer Class</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://tutarchive.com/2009/09/using-regex-regular-expressions-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking Username Availability with Mootools and Request.JSON</title>
		<link>http://tutarchive.com/2009/09/checking-username-availability-with-mootools-and-request-json/</link>
		<comments>http://tutarchive.com/2009/09/checking-username-availability-with-mootools-and-request-json/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 01:05:59 +0000</pubDate>
		<dc:creator>TutArchive</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Checking Username]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Mootools]]></category>

		<guid isPermaLink="false">http://tutarchive.com/?p=213</guid>
		<description><![CDATA[This tutorial will teach you how to check username availability with Mootools' Request.JSON and PHP/MySQL
In this tutorial you will learn how to use Mootools' Request.JSON function to check a username against an array or database. In this example we will be using a simple MySQL database. I will try to do as much hand holding [...]


Related posts:<ol><li><a href='http://tutarchive.com/2009/09/object-oriented-programming-with-javascript-timer-class/' rel='bookmark' title='Permanent Link: Object Oriented Programming with JavaScript : Timer Class'>Object Oriented Programming with JavaScript : Timer Class</a></li><li><a href='http://tutarchive.com/2009/09/flex-alert-listen-to-the-buttons/' rel='bookmark' title='Permanent Link: Flex Alert! Listen to the buttons'>Flex Alert! Listen to the buttons</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>This tutorial will teach you how to check username availability with Mootools' Request.JSON and PHP/MySQL</p>
<p>In this tutorial you will learn how to use Mootools' Request.JSON function to check a username against an array or database. In this example we will be using a simple MySQL database. I will try to do as much hand holding as I can, but having a little experience with PHP and MySQL will be a plus.</p>
<h1>Tutorial Details</h1>
<ul>
<li>PHP Server and MySQL Database required</li>
<li>Difficulty: Beginner/Intermediate</li>
<li>Estimated Completion Time: 30 - 45 Minutes</li>
</ul>
<p><!-- 600 --></p>
<h1>Step 1 - The Setup</h1>
<p>We are going to create a simple database and add a table. After that we will add a username into the database.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #990099; font-weight: bold;">IF <span style="color: #CC0099; font-weight: bold;">NOT</span> EXISTS</span> ajax_users <span style="color: #FF00FF;">&#40;</span>
	id <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #000033;">,</span>
	user_name <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">128</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> ajax_users <span style="color: #990099; font-weight: bold;">VALUES</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'NULL'</span><span style="color: #000033;">,</span><span style="color: #008000;">'matt'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<h1><span id="more-213"></span></h1>
<h1>Step 2 - The Skeleton</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/skeleton.png" alt="preview" width="600" height="253" /></div>
<p>For the first step we will create a simple page with one input field for the username and a submit button. Go ahead and open your favorite coding app - mine happens to be Coda - and create a new blank document named index.php. First I'll show you the end result code for this step and then I'll explain it in detail. I find that re-writting the code myself helps it stick, but you can copy and paste if you want.</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;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span>
&nbsp;
    		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;signup&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;form&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    						<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user_name&quot;</span>&gt;</span>Username<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
    						<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user_name&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</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>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Sign Up Now!&quot;</span> <span style="color: #66cc66;">/</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>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
&nbsp;
    		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</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: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Now we've got a pretty basic site layout. It will start to come together in step 2 so don't worry if it doesn't really look like much right now.</p>
<h1>Step 3 - A little Style</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/styled.png" alt="preview" width="600" height="253" /></div>
<p>Feel free to style this up however you like, or use the CSS file from the source code.</p>
<h1>Step 4 - The Javascript Setup</h1>
<p>We are going to need to include the Mootools framework into our php file. Without this, we can't use any of Mootools' classes or functions for our script. There are two ways of doing this. The first way is to use Google's AJAX Libraries API to link to the file. You can view the path <a href="http://code.google.com/apis/ajaxlibs/documentation/#mootools" target="_blank">Here</a>. The Google libraries give you access to many frameworks so take a look around after you're done the tutorial. To speed things up, we can just use the piece of code below. Place this in your section of your php file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/mootools/1.2.3/mootools-yui-compressed.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javacript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The second way is to head over to the <a href="http://mootools.net/" target="_blank">Mootools site</a></p>
<p>Now that we have the Mootools framework included in our file, we can go ahead and create a new file called main.js, or whatever you want to name it. Once this file has been created lets include it in our php file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;path-to-your-file/main.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javacript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Go ahead and place that at the bottom of our php file. If you haven't already, let's open up our main.js file.</p>
<h1>Step 5 - The Mootools</h1>
<p>This part can get a little tricky. Make sure the two files you have open are index.php and main.js as we will be moving back and forth between the files to give you a better idea of how Mootools interacts with the elements in index.php.</p>
<p>The first piece of code we are going to add to main.js tells our Mootools script to execute some code when the DOM has loaded.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	window.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'domready'</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: #006600; font-style: italic;">//We are going to fill this with Mootools goodness</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now that the main business is taken care of, we can get our hands dirty.</p>
<h1>Step 6 - Adding Events</h1>
<p>We need to figure out a way to find out when a user has interacted with our user name input field. We do this using events. Events are Mootools' way of performing some action(s) when a user does something. This can include clicking on a link, pressing down a key, releasing a key, mousing over etc. For this example we are going to fire an event when the user releases a key in the username field.</p>
<p>Before we add the event, we need to give out user name input an ID. Without an ID, Mootools doesn't know which input we are talking about when we tell it to add an event.</p>
<p>Go ahead and add an ID to your user name input in index.php</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;user_name&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user_name&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>Ok, I swear we will start coding some Mootools right now. Switch back to main.js. Inside your window event, add this code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'user_name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'keyup'</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: #006600; font-style: italic;">//This is what is fired when the user releases a key inside the username input</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h1>Step 7 - The Request</h1>
<p>Now that we have the event linked up, we can build the request to send when the event is fired. We are going to put this piece of code inside out event.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	...
	<span style="color: #660066;">The</span> start of our event
	...
&nbsp;
    	<span style="color: #003366; font-weight: bold;">new</span> Request.<span style="color: #660066;">JSON</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    		url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;inc/php/json.php&quot;</span><span style="color: #339933;">,</span>
    		onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    		<span style="color: #009900;">&#125;</span>
    	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'signup'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	...
	<span style="color: #660066;">The</span> end of our event
	...</pre></div></div>

<p>Pretty simple looking, eh?! We start off by declaring our request. The first variable is url. This is the path to our PHP that houses our JSON magic. For now, just put in a path to a future file. The second variable is onSuccess. This is a function that is fired if our request is successful. This is where we will put most of our remaining code. Our last little bit, which is easy to look over is the .get($('signup')) variable trailing our request. This takes all our info from our form in index.php and sends it with the JSON request. Without this, the request isn't sending any data, and is pretty much useless. We've now made it useful!</p>
<p>We should probably make our JSON file right now so we don't run into any errors.</p>
<h1>Step 8 - The JSON</h1>
<p>The concept behind our JSON file is pretty simple in theory. It takes our variables, does whatever we want with it, and then sends it back to our main.js file, all behind the scenes. This is awesome. Take a second to collect yourself.</p>
<p>Ok, now we are all calm, lets create a new file called json.php. If you added the path to your main.js file, name it the same and place it into proper folder. Open this sucker up!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//setup a blank variable</span>
<span style="color: #666666; font-style: italic;">//we will use this as an array to send back</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span></pre></div></div>

<p>Simple right? The first step is creating a null variable that we will be using as an array later on. Next, we need to connect to our database.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//connect to the mysql database</span>
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error connecting to mysql'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tutorials'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error connecting to table'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We should be all connected. Fill in your database information above. To make sure everything is running smoothly, point to your json.php file. If the page is blank, we are golden. If you see database connection errors, we have a problem. This is usually just a misspelled host/username/password. Double check!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//format the variables</span>
<span style="color: #000088;">$user_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//check the database for any users named $user_name</span>
<span style="color: #000088;">$grab_user</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `user_name` FROM `ajax_users` WHERE `user_name` = '<span style="color: #006699; font-weight: bold;">$user_name</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//check if the query returned anything</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$grab_user</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//no user by that name</span>
	<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'success'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//oops, already taken</span>
	<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'error'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>All the variables sent to our json our sent as $_GET. If you've worked with forms before, this shouldn't be anything different. If you haven't worked with PHP forms before, please take a quick look at this page.</p>
<p>We are putting the $_GET variable into a new variable to clean everything up. By wrapping the $_GET variable in the mysql_real_escape_string() function, we are making sure to combat mysql injection. Injection is bad!</p>
<p>Next is the query. We are grabbing any rows from our MySQL database where the user_name row is equal to whatever the user has typed into the user_name input. If the query returns 0, there is no user name match.</p>
<p>If there is no match, we add an action variable to our result array and give it a value of success. If there is a match, we simply give it a value of error.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//send the response back</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Finally, we add a user_name variable to the result array and give it a value of our $_GET variable and send it back to main.js using the json_encode() function.</p>
<p>When the JSON is encoded and sent back to the main.js file it looks like the code below</p>
<pre>{"action":"success","user_name":"matt"}</pre>
<p>That ends the json file, you can save it and close it. You will not need it for this example anymore! Switch back to main.js</p>
<h1>Step 9 - Dealing with the Request</h1>
<p>We've sent the request, we've checked if the user name exists and we sent the response. So what now? Now we are going to use Mootools to sort through the response and alert the user. How does main.js see what the response is? If we take a quick look back at our onSuccess function, you'll notice that the only variable passed in the function is response. This is the variable that now houses your JSON response. Please add this code inside our onSuccess function.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>response<span style="color: #339933;">.</span>action <span style="color: #339933;">==</span> <span style="color: #0000ff;">'success'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//We are good!</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Username is taken, ouch?!</span>
alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Username Taken'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We haven't been able to test if our little application is even working right now, so lets take a second to do a quick test. Point your browser to index.php and type <em>matt</em> into your user_name input. Once you are done typing, <em>matt</em> an alert should popup saying <em>Username Taken</em>. You can now delete that alert; it is not needed anymore.</p>
<p>Alerts are boring. They're ugly, they're not very user friendly. Alerts are bad! We need a way to alert the user in a nice, design and user friendly way to alert the user. Open up your style.css and add some styles to your input.</p>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/error_notext.png" alt="preview" width="600" height="253" /></div>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">input.success<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#9ad81f</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
input.error<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#b92929</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>We have our styles, and we are receiving a response, lets change the inputs style depending on the response.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>removeClass<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>addClass<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'success'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<div><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/ok_notext.png" alt="preview" width="600" height="253" /></div>
<p>We are taking our input and making sure Mootools can find it using $(). After that we add/remove our classes. We make sure to remove the error class incase the script has already added it to our input, then we add the success class. This stops the scripts from adding multiple classes to the input and making it look like input.error.success.error.success. For the response that throws an error, simply reverse the add/remove order.</p>
<p>Give that a test. The input box should have a green outline until you enter in <em>matt</em> as a user name. The input box should then turn red.</p>
<p>That's it. That's the bare bones version of this script. If you want, you can stop reading now and show-off your new tricks to your friends, or you can continue reading. I'm going to expand on the script to make it just a little bit more user friendly.</p>
<h1>Step 10 - 1000 Requests</h1>
<div><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/json_requests.png" alt="preview" width="600" height="253" /></div>
<p>Right now, the script is firing every time a user releases a key. What if you force users to have user names longer than 3 characters. We are basically wasting 3 requests when really, we can just tell the script not to fire unless the input value is more then 3 characters long. This will cut back on the number of requests we are sending to the JSON script!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #660066;">The</span> start of our user <span style="color: #000066;">name</span> event
...
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> input_value <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>input_value.<span style="color: #660066;">length</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		...
		<span style="color: #660066;">Request</span> Event
		...
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
...
<span style="color: #660066;">The</span> end of our user <span style="color: #000066;">name</span> event
...</pre></div></div>

<p>If we wrap our request with the above code, it will only fire the request when the input value is greater than 3. First we put the value into our variable using this.value. <em>this</em> represents our user_name input. Next we check if the length of our value is greater than 3. We do this by using input_value.length. Give it a quick test.</p>
<h3>Step 11 - Visuals Please</h3>
<div><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/error_text.png" alt="preview" width="600" height="253" /></div>
<p>Remember in our JSON file we were sending our user name value back with our response. This is why. Open up index.php and add a p right underneath our input.</p>
<p>Now that we have our p with an id of response, we can make Mootools insert some text into it. Open up main.js and place this code inside the onSuccess function.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'response'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'&lt;em&gt;'</span><span style="color: #339933;">+</span>response.<span style="color: #660066;">user_name</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/em&gt; is Available'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<div><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/ok_text.png" alt="preview" width="600" height="253" /></div>
<p>Mootools takes $('response') and uses the set() function to insert some text. The first option is what kind of data are we setting. This can either be html or text. Because we are sending an <em> </em> tag are a result, we are using html. We are using response.user_name to grab the user_name variable from our JSON response to keep the user up to date. For the error section, copy over the piece of code and change around the text a little bit to let the user know that the user name is taken.</p>
<h1>Step 12 - Submission</h1>
<p>Right now, even though we are saying that the user name is taken, the user can still submit the form. This means you would have to use PHP to do another level of error checking. This is unnecessary when we could just check right now! Open up index.php and find our submit button. Lets disable it!</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;submit_button&quot;</span> <span style="color: #000066;">disabled</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;disabled&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Sign Up Now!&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<div><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/disabled.png" alt="preview" width="600" height="253" /></div>
<p>We gave out submit button an id of <em>submit_button</em> so that Mootools can talk to it. Near the close tag we also added <em>disabled</em>. If you point your browser to index.php and try and click on the button, you will notice that nothing will happen. The form has been disabled. Open up main.js</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit_button'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">disabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></pre></div></div>

<div><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/441_mootools/tutorial_img/styled.png" alt="preview" width="600" height="253" /></div>
<p>If we add that piece of code in our response.success area, it will enable the button. Simply add it to the reponse.error section, change false to true and give it a test. When the user name is available, you should be able to click the button. When taken, the button should be disabled.</p>
<h1>Step 13 - The Cleanup</h1>
<p>The user has inserted some text, and then deleted all the text from the input. If you notice all the alerts stay on the screen. This is a bit messy. We should probably fix that. Open main.js.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #660066;">The</span> end of our user <span style="color: #000066;">name</span> event
...
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'user_name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'blur'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
   	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
   		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'user_name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'success'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'user_name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'response'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit_button'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">disabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
   	<span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>hen the user clicks away from the input, it will fire the event <em>blur</em>. If the input box value is empty, we remove all classes, set the response p to empty and disable the button. Nice and tidy!</p>
<h1>The End</h1>
<p>I hope this tutorial has helped to teach you some of the fundamentals when using simple JSON requests and interacting with elements on the page with Mootools</p>


<p>Related posts:<ol><li><a href='http://tutarchive.com/2009/09/object-oriented-programming-with-javascript-timer-class/' rel='bookmark' title='Permanent Link: Object Oriented Programming with JavaScript : Timer Class'>Object Oriented Programming with JavaScript : Timer Class</a></li><li><a href='http://tutarchive.com/2009/09/flex-alert-listen-to-the-buttons/' rel='bookmark' title='Permanent Link: Flex Alert! Listen to the buttons'>Flex Alert! Listen to the buttons</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://tutarchive.com/2009/09/checking-username-availability-with-mootools-and-request-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Lightbox</title>
		<link>http://tutarchive.com/2009/09/jquery-lightbox/</link>
		<comments>http://tutarchive.com/2009/09/jquery-lightbox/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 15:36:09 +0000</pubDate>
		<dc:creator>TutArchive</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutarchive.com/?p=210</guid>
		<description><![CDATA[I couldn't tell you how many lightboxes I've used over the last few month. This specific lightbox was designed as a plugin for the jQuery library. It works perfectly, and more importantly, requires no additional markup to your document. You only need to call it from your Javascript file. You'll have zero problems!


Download


Related posts:15+ jQuery [...]


Related posts:<ol><li><a href='http://tutarchive.com/2009/09/15-jquery-popup-modal-dialog-plugins-and-tutorials/' rel='bookmark' title='Permanent Link: 15+ jQuery Popup Modal Dialog Plugins and Tutorials'>15+ jQuery Popup Modal Dialog Plugins and Tutorials</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I couldn't tell you how many lightboxes I've used over the last few month. This specific lightbox was designed as a plugin for the jQuery library. It works perfectly, and more importantly, requires no additional markup to your document. You only need to call it from your Javascript file. You'll have zero problems!</p>
<div style="text-align: center;"><img src="http://nettuts.s3.amazonaws.com/119_lightbox/lightboxheader.jpg" alt="Lightbox" /></div>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/119_lightbox/lightbox.jpg" alt="Lightbox" /></div>
<p><a href="http://leandrovieira.com/projects/jquery/lightbox/" target="_blank">Download</a></p>


<p>Related posts:<ol><li><a href='http://tutarchive.com/2009/09/15-jquery-popup-modal-dialog-plugins-and-tutorials/' rel='bookmark' title='Permanent Link: 15+ jQuery Popup Modal Dialog Plugins and Tutorials'>15+ jQuery Popup Modal Dialog Plugins and Tutorials</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://tutarchive.com/2009/09/jquery-lightbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>11 Classic CSS Techniques Made Simple with CSS3</title>
		<link>http://tutarchive.com/2009/09/11-classic-css-techniques-made-simple-with-css3/</link>
		<comments>http://tutarchive.com/2009/09/11-classic-css-techniques-made-simple-with-css3/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 16:10:37 +0000</pubDate>
		<dc:creator>TutArchive</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[Animations]]></category>
		<category><![CDATA[Background Size]]></category>
		<category><![CDATA[Border Image]]></category>
		<category><![CDATA[Box Shadow]]></category>
		<category><![CDATA[Columns]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Fancy Font]]></category>
		<category><![CDATA[Multiple Backgrounds]]></category>
		<category><![CDATA[Opacity]]></category>
		<category><![CDATA[RGBA]]></category>
		<category><![CDATA[Rounded Corners]]></category>
		<category><![CDATA[Text Shadow]]></category>

		<guid isPermaLink="false">http://tutarchive.com/?p=186</guid>
		<description><![CDATA[CSS3? What's that?!
I'm sure you've heard of CSS in general. CSS3 isn't that much different, in terms of syntax; however, the power of CSS3 is much greater. As you'll see in these eleven techniques, you can have multiple backgrounds, dynamically resize those backgrounds, border radiuses, text shadows, and more!
Here's what the official (or at least, [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<h3>CSS3? What's that?!</h3>
<p>I'm sure you've heard of CSS in general. CSS3 isn't that much different, in terms of syntax; however, the power of CSS3 is much greater. As you'll see in these eleven techniques, you can have multiple backgrounds, dynamically resize those backgrounds, border radiuses, text shadows, and more!</p>
<p>Here's what the official (or at least, what I consider official) website of CSS3, <a href="http://www.css3.info/">css3.info</a>, has to say about CSS3:</p>
<blockquote><p>CSS3 is the new kid in the stylesheet family. It offers exciting new possibilities to create an impact with your designs, allows you to use more diverse style sheets for a variety of occasions and lots more.</p></blockquote>
<p>Here are the 11 techniques that I'll be showing you how to recreate with CSS3. I'll show you how to create them using CSS2 (or JavaScript), and then with CSS3 properties. <em>Remember - these effects will only work in modern browsers that implement these CSS3 features. Your best option is to view these with Safari 4.</em></p>
<ol>
<li><strong>Rounded Corners</strong></li>
<li><strong>Box Shadow</strong></li>
<li><strong>Text Shadow</strong></li>
<li><strong>Fancy Font</strong></li>
<li><strong>Opacity</strong></li>
<li><strong>RGBA</strong></li>
<li><strong>Background Size</strong></li>
<li><strong>Multiple Backgrounds</strong></li>
<li><strong>Columns</strong></li>
<li><strong>Border Image</strong></li>
<li><strong>Animations</strong></li>
</ol>
<p><span id="more-186"></span></p>
<h1>1. Rounded Corners</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/corners.jpg" alt="Rounded Corners" /></div>
<p>Probably my favorite on of this list, rounded corners provide a developer with so many options. You can create a rounded corner button in seconds. My favorite thing to do is set a gradient background to repeat along the x-axis and then apply rounded corners to make a very nice looking Web 2.0 button.</p>
<p>You can simulate rounded corners by using <strong>four extra divs</strong> or by using JavaScript. Though, a user doesn't see these smooth corners if they have JavaScript disabled, I think that's fine as long as the website still functions as it should. You can <a href="http://cssglobe.com/post/3714/css-sprites-rounded-corners/">read up</a> on this method if you would prefer to use pure CSS in making rounded corners.</p>
<p><strong>Classic Way</strong></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;">script</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.3.2/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:0--&gt;</span><span style="color: #009900;">&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;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/jquery.corners.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:1--&gt;</span><span style="color: #009900;">&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>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:2--&gt;</span><span style="color: #009900;">&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;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p>The classical method uses jQuery along with a JavaScript plugin called <a href="http://plugins.jquery.com/project/corners">Corners</a>.</p>
<p><strong>CSS3 Way</strong></p>
<p>The classical method uses jQuery along with a JavaScript plugin called <a href="http://plugins.jquery.com/project/corners">Corners</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p>As you can see, all that you need to do is specify three CSS3 properties. Eventually, it will only be one; you have to use three now because different browsers use different property names.</p>
<h1>2. Box Shadow</h1>
<div><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/shadow.jpg" alt="Box Shadow" /></div>
<p>Box shadows provide you with a very powerful tool. 99% of the time when I'm desigining, I find myself using drop shadows for something. Once again, I'll be using a jQuery plugin to take care of the classic way because honestly, trying to figure it out with just CSS is confusing. Why should I waste my time fiddling with negative margins when there's already something written that does the job for me? As long as my design looks fine when people have JavaScript disabled, I'm perfectly content using a jQuery plugin.</p>
<p><strong>Classic Way</strong></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;">script</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.3.2/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:3--&gt;</span><span style="color: #009900;">&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;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/jquery.dropShadow.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:4--&gt;</span><span style="color: #009900;">&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>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:5--&gt;</span><span style="color: #009900;">&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;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p>I'm using the <a href="http://eyebulb.com/dropshadow/">dropShadow</a> plugin. Simple and what I wanted; though I would prefer to use just CSS <img src='http://tutarchive.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { box-shadow: 5px 5px 2px black; -moz-box-shadow: 5px 5px 2px black; -webkit-box-shadow: 5px 5px 2px black; } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<h1>3. Text Shadow</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/textshadow.jpg" alt="Text Shadow" /></div>
<p>If you've ever read a tutorial about how to make the letterpress effect in Photoshop, you'll know that the drop shadow effect is used. It's really simple to create letterpressed text, just follow <a href="http://line25.com/tutorials/create-a-letterpress-effect-with-css-text-shadow">this tutorial at Line25</a> by Chris Spooner.</p>
<p><strong>Classic Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .font { font-size: 20px; color: #2178d9; } .fonts { position: relative; } .fonts .font { position: absolute; z-index: 200; } .fonts .second { top: 1px; color: #000; z-index: 100; } --&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;fonts&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;font&quot;</span>&gt;</span>The quick brown fox jumps over the lazy dog.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;font second&quot;</span>&gt;</span>The quick brown fox jumps over the lazy dog.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Instead of using a jQuery plugin this time, I just used some simple CSS tricks to absolutely position the text behind the other copy of text. The only bad thing about not using CSS3 for this situation is that you will get two copies of the text if CSS is disabled.</p>
<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .font { font-size: 20px; color: #2178d9; } .font { text-shadow: 0 1px 0 #000; } --&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;font&quot;</span>&gt;</span>The quick brown fox jumps over the lazy dog.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></pre></div></div>

<h1>4. Fancy Font</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/font.jpg" alt="Fancy Font" /></div>
<p>We've dreamed about it for a long time now, but you can finally display "fancy fonts" on the web <strong>without</strong> relying on JavaScript. Of course this causes some issues with allowing paid fonts to be distributed over the internet. Anyhow, I present you with @font-face.</p>
<p><strong>Classic Way</strong></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;">script</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.3.2/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:6--&gt;</span><span style="color: #009900;">&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;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/cufon.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:7--&gt;</span><span style="color: #009900;">&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;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/loyal.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:8--&gt;</span><span style="color: #009900;">&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>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:9--&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- .font { font-size: 20px; } --&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;font&quot;</span>&gt;</span>The quick brown fox jumps over the lazy dog.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></pre></div></div>

<p>I decided to use Cufón to replace the text. I'm not going to explain how to use it because Jeffrey has an awesome screencast already.</p>
<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- @font-face { font-family: 'Loyal'; src: url('loyal.ttf'); } .font { font-family: Loyal; font-size: 20px; } --&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;font&quot;</span>&gt;</span>The quick brown fox jumps over the lazy dog.
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></pre></div></div>

<p>We create a font family with @font-face and then use it as a value for font-family. Michael Owens wrote an article here about a month ago which explains @font-face quite well.</p>
<h1>5. Opacity</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/opacity.jpg" alt="Opacity" /></div>
<p>If you've visited the <a href="http://envato.com/">Envato website</a> redesign lately, you might have noticed that there are a lot of transparent elements. Though this is achieved with transparent PNGs, you can achieve a similar effect by using the opacity property. Now, the opacity property has been around for a while, but our beloved IE has its own properties.</p>
<p><strong>Classic Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { opacity: .6; // all modern browsers (this is CSS3) -ms-filter: &quot;progid:DXImageTransform.Microsoft.Alpha(Opacity=50)&quot;; // IE 8 filter: alpha(opacity=60); // IE 5-7 } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { opacity: .6; } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<h1>6. RGBA</h1>
<div><img src="http://nettuts.s3.amazonaws.com/430_cssTips/images/rgba.jpg" alt="RGBA" /></div>
<p>Everyone knows what RGB stands for (red, green, blue), but what does the A stand for? It stands for alpha, which refers to the transparency.</p>
<p>Other than rounded corners, RGBA is my next most used CSS3 property. Sometimes I just want to add a few light white/black background to navigation links when a user hover overs them. It's much easier than creating a new image for each color; however, with a little PHP it makes things a lot easier.</p>
<p><strong>Classic Way</strong></p>
<p>Seeing as how this isn't a PHP article, I won't be going over the PHP. Just save this file as rgba.php and when you need a certain RGBA color, make the background "color" as url(rgba.php?r=R&amp;g=G&amp;b=B&amp;a=A).</p>
<p>Now just apply that to a div...</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { background: url(rgba.php?r=239&amp;#038;g=182&amp;#038;b=29&amp;#038;a=.25); } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strick" style="font-family:monospace;">&lt;!-- .box { background: rgba(239, 182, 29, .25); } --&gt;
&lt;div class=&quot;box&quot;&gt;
	&lt;!--CONTENT--&gt;&lt;/div&gt;</pre></div></div>

<h1>7. Background Size</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/bgsize.jpg" alt="Background Size" /></div>
<p>The background size property is an amazing thing to have on your tool belt when you're creating a liquid layout. An example of this could be when you have a background image for a container that is for the sidebar. The classic way of doing this would require tweaking to have the image repeat along the y-axis, but with CSS3 it's like adding another background property.</p>
<p><strong>Classic Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { position: relative; overflow: hidden; } 	.box img { 	position: absolute; 	top: 0; 	left: 0; 	width: 50%; 	height: 50%; 	z-index: 100; 	} 	.box .content { 	position: absolute; 	z-index: 200; 	} --&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;box&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;content&quot;</span>&gt;</span>
		<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&gt;</span><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;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://nettuts.s3.amazonaws.com/423_screenr/200x200.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { background: #ccc url(http://nettuts.s3.amazonaws.com/423_screenr/200x200.jpg) no-repeat; -webkit-background-size: 50%; /* Safari */ -o-background-size: 50%; /* Opera */ -khtml-background-size: 50%; /* Konqueror */ } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<h1>8. Multiple Backgrounds</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/bgs.jpg" alt="Multiple Backgrounds" /></div>
<p>Ah, multiple backgrounds. Now this give developers a very powerful tool. I can think of so many things that require multiple divs just to have more than one background. The most common place I can see this being helpful is in a header section of the website, but that's just the first thing I thought of.<br />
<strong>Classic Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strick" style="font-family:monospace;">&lt;!-- .box { width: 200px; height: 150px; background: url(images/bg.png) repeat-x; } 	.box2 { 	width: 100%; 	height: 100%; 	background: url(images/text.png) center center no-repeat; 	} --&gt;
&lt;div class=&quot;box&quot;&gt;
&lt;div class=&quot;box2&quot;&gt;
		&lt;!--CONTENT--&gt;&lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>The classic method is pretty obvious, just wrap the div with another div and so on for each background you need. Produces lovely looking code, doesn't it?</p>
<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { width: 200px; height: 150px; background: url(images/text.png) center center no-repeat, url(images/bg.png) repeat-x; } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p>The syntax is really easy to pick up on this one. All you do for the multiple backgrounds is add a comma in between each one! However, once again, this is a limited property and is only in Safari.</p>
<h1>9. Columns</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/columns.jpg" alt="Columns" /></div>
<p>This is the most interesting CSS3 property I've come by. It's not something you see a lot in web design. Myself, I've only seen newspaper-like columns once or twice; however, I love how the effect looks when done correctly. Normally you would separate the content into divs and float those divs, but I found a <a href="http://welcome.totheinter.net/columnizer-jquery-plugin/">jQuery plugin</a> which dynamically renders the columns.</p>
<p><strong>Classic Way</strong></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;">script</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.3.2/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:10--&gt;</span><span style="color: #009900;">&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;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/jquery.columnize.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:11--&gt;</span><span style="color: #009900;">&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>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:12--&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- .column { padding-right: 10px; } .column.last { padding: 0; } --&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;columns&quot;</span>&gt;</span>
&nbsp;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum accumsan mi. Maecenas id dui a magna tempor pretium. Quisque id enim. Proin id tortor. Curabitur sit amet enim vitae quam pharetra imperdiet. Nulla diam ante, pellentesque eu, vestibulum non, adipiscing nec, eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis a nunc. Donec non dui a velit pulvinar gravida. Nunc rutrum libero vel tortor. Duis sed mi eu metus tincidunt ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In purus lorem, aliquam ac, congue ac, vestibulum quis, felis. Aliquam non sapien.
&nbsp;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum accumsan mi. Maecenas id dui a magna tempor pretium. Quisque id enim. Proin id tortor. Curabitur sit amet enim vitae quam pharetra imperdiet. Nulla diam ante, pellentesque eu, vestibulum non, adipiscing nec, eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis a nunc. Donec non dui a velit pulvinar gravida. Nunc rutrum libero vel tortor. Duis sed mi eu metus tincidunt ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In purus lorem, aliquam ac, congue ac, vestibulum quis, felis. Aliquam non sapien.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>I've added a little padding to the columns just so the text isn't smashed up against each other.</p>
<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .columns { -moz-column-count: 2; -webkit-column-count: 2; } --&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;columns&quot;</span>&gt;</span>
&nbsp;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum accumsan mi. Maecenas id dui a magna tempor pretium. Quisque id enim. Proin id tortor. Curabitur sit amet enim vitae quam pharetra imperdiet. Nulla diam ante, pellentesque eu, vestibulum non, adipiscing nec, eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis a nunc. Donec non dui a velit pulvinar gravida. Nunc rutrum libero vel tortor. Duis sed mi eu metus tincidunt ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In purus lorem, aliquam ac, congue ac, vestibulum quis, felis. Aliquam non sapien.
&nbsp;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum accumsan mi. Maecenas id dui a magna tempor pretium. Quisque id enim. Proin id tortor. Curabitur sit amet enim vitae quam pharetra imperdiet. Nulla diam ante, pellentesque eu, vestibulum non, adipiscing nec, eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis a nunc. Donec non dui a velit pulvinar gravida. Nunc rutrum libero vel tortor. Duis sed mi eu metus tincidunt ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In purus lorem, aliquam ac, congue ac, vestibulum quis, felis. Aliquam non sapien.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>There are a handful of other CSS3 column properties that you can apply, but for demonstrative purposes, I only specified the number of columns. If you'd like to learn more about these other properties, check out <a href="http://www.css3.info/preview/multi-column-layout/">the multi-column page at CSS3.info</a>.</p>
<h1>10. Border Image</h1>
<div><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/border.jpg" alt="Border Image" /></div>
<p>I had no clue about the border image property until I upgraded to Firefox 3.5 and went to <a href="http://www.blog.spoongraphics.co.uk/">Chris Spooner's website</a> and saw that his post images had image borders. I personally don't have any interest in this property, but that's not going to stop me from explaining how to achieve it.</p>
<p><strong>Classic Way</strong></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;">script</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.3.2/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:13--&gt;</span><span style="color: #009900;">&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;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/jquery.borderImage.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:14--&gt;</span><span style="color: #009900;">&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>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:15--&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- .box { border-width: 20px; } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p>Instead of spending the time creating multiple divs and repeating the background image around the div, I found a jQuery plugin that does the work for me. It's called <a href="http://plugins.jquery.com/project/jbi">borderImage</a> and works just like it should.</p>
<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- .box { border-width: 20px; -webkit-border-image: url(images/border.png) 27 round; -moz-border-image: url(images/border.png) 27 round; border-image: url(images/border.png) 27 round; } --&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p>As you can see, the border image property is a bit odd. <a href="http://www.w3.org/TR/css3-background/#the-border-image">W3</a> explains how it gets calculated <strong>MUCH</strong> better.</p>
<h1>11. Animations</h1>
<div style="text-align: center;"><img style="display: inline;" src="http://nettuts.s3.amazonaws.com/430_cssTips/images/animation.jpg" alt="Animations" /></div>
<p>Alright, who doesn't love to see some element gently slide to the left or fade in when you hover over something? Animations are great to increase user interface, but make sure that you don't go over board! The only browsers that support CSS3 animations are Webkit based browsers. The only other way to display animations is to use JavaScript. I'll be using jQuery because it's my favorite JavaScript library (if you haven't guessed by now).</p>
<p><strong>Classic Way</strong></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;">script</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.3.2/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:16--&gt;</span><span style="color: #009900;">&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>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:17--&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--</span>
&nbsp;
<span style="color: #808080; font-style: italic;">.box {</span>
&nbsp;
<span style="color: #808080; font-style: italic;">position: relative;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">}</span>
&nbsp;
<span style="color: #808080; font-style: italic;">--&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p><strong>CSS3 Way</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--</span>
&nbsp;
<span style="color: #808080; font-style: italic;">.box {</span>
&nbsp;
<span style="color: #808080; font-style: italic;">position: relative;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-webkit-transition: top 300ms linear;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">}</span>
&nbsp;
<span style="color: #808080; font-style: italic;">.box:hover {</span>
&nbsp;
<span style="color: #808080; font-style: italic;">top: 20px;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">}</span>
&nbsp;
<span style="color: #808080; font-style: italic;">--&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;box&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--CONTENT--&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>

<p>Both of these code snippets do the same thing: slide the div 20 pixels down over the course of 300 ms. Remember, the CSS3 code only works in Webkit browsers!</p>
<h1>Conclusion</h1>
<p>There you have it: 11 CSS techniques that will become much easier with CSS3 in the (hopefully near) future. Obviously, it'll be a while before we can 100% depend on these properties across all browsers.</p>
<p>Don't forget to review these other Nettuts+ tutorials that discuss CSS3:</p>
<p style="text-align: right;">From <strong>TutPlus</strong></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://tutarchive.com/2009/09/11-classic-css-techniques-made-simple-with-css3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
