<?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>Tutorialzine &#187; CSS</title>
	<atom:link href="http://tutorialzine.com/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://tutorialzine.com</link>
	<description>Web Development Tutorials &#38; Resources</description>
	<lastBuildDate>Thu, 23 May 2013 10:59:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Let&#8217;s Make A Simple AJAX Note Taking App</title>
		<link>http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/</link>
		<comments>http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/#comments</comments>
		<pubDate>Thu, 13 Sep 2012 19:28:57 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=2408</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/09/2408-620x340.jpg" class="attachment-tzmedium" alt="Let&#039;s Make A Simple AJAX Note Taking App" /></a></div> In this tutorial we will be making a simple app with PHP and jQuery, that will let users write notes and save them as text files on the server.]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/09/2408-620x340.jpg" class="attachment-tzmedium" alt="Let&#039;s Make A Simple AJAX Note Taking App" /></a></div> <p>In this tutorial we will be making a simple app with PHP and jQuery that lets users write notes. The notes are going to be saved in plain text files on the server. It demonstrates how to read and write files in PHP, how to resize a textarea with jQuery, depending on the text inside it, and how to create a simple AJAX interaction.</p>
<p>Grab a copy of the demo from the button above and read on!</p>
<h3>The HTML</h3>
<p>To start off, we need to create a regular HTML5 document. I have including only the important bits below, but you can see the rest in <em>index.php</em>. Notice that I have placed the PHP code in the same file for simplicity.</p>
<h4>index.php</h4>
<pre class="brush:html">&lt;div id="pad"&gt;
	&lt;h2&gt;Note&lt;/h2&gt;
	&lt;textarea id="note"&gt;&lt;?php echo $note_content ?&gt;&lt;/textarea&gt;
&lt;/div&gt;</pre>
<p>That is all the markup that we need for the note! Of course, we will be heavily styling it with CSS in a few minutes. I&#8217;ve also included the jQuery library further down the page (before the closing body tag) along with our <em>script.js </em>file, but I won&#8217;t be showing it here. The important thing is that PHP echo statement inside the textarea. It prints the last saved note of the user.</p>
<h3>The PHP</h3>
<p>The PHP code of the example is straightforward. What it does is to <a href="http://php.net/manual/en/function.file-get-contents.php" target="_blank">read</a> and present the contents of the note on page load, and to <a href="http://www.php.net/manual/en/function.file-put-contents.php" target="_blank">write</a> to it when an AJAX request is sent by jQuery. This will cause the note file to be overridden.</p>
<h4>index.php</h4>
<pre class="brush:php">$note_name = 'note.txt';
$uniqueNotePerIP = true;

if($uniqueNotePerIP){

	// Use the user's IP as the name of the note.
	// This is useful when you have many people
	// using the app simultaneously.

	if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
		$note_name = 'notes/'.$_SERVER['HTTP_X_FORWARDED_FOR'].'.txt';
	}
	else{
		$note_name = 'notes/'.$_SERVER['REMOTE_ADDR'].'.txt';
	}
}

if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
	// This is an AJAX request

	if(isset($_POST['note'])){
		// Write the file to disk
		file_put_contents($note_name, $_POST['note']);
		echo '{"saved":1}';
	}

	exit;
}

$note_content = '';

if( file_exists($note_name) ){
	$note_content = htmlspecialchars( file_get_contents($note_name) );
}</pre>
<p>Notice the <strong>$uniqueNotePerIP</strong> variable. I am using this on the demo so that every user gets a unique note. This setting will cause each note to be saved with the visitor&#8217;s IP address as a name. You can set it to false, if you want everyone to share a single note, but keep in mind that if two people edit the note simultaneously, the one that saves last will override it, and in rare cases the note itself may get corrupted.</p>
<p>Next up, the jQuery code!</p>
<div id="attachment_2413" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/09/simple-note-taking-app-ajax/"><img class="size-full wp-image-2413" title="AJAX Note Taking App" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/09/illustration.jpg" alt="AJAX Note Taking App" width="620" height="460" /></a><p class="wp-caption-text">AJAX Note Taking App</p></div>
<h3>The jQuery</h3>
<p>jQuery&#8217;s job in this app, would be to listen for changes in the text area, and send them with an AJAX <strong>post</strong> request back to index.php, where the text is written to a file.</p>
<p>The usual approach would be to bind a handler to the <em>keypress</em> event, but in certain cases this won&#8217;t be enough as the user may simply paste text into the textarea, choose an auto-correct suggestion by their browser or undo a change. Luckily for us, there is another event that handles all of these cases. It is the <strong>input</strong> event, which is supported by all modern browsers (<a href="http://help.dottoro.com/ljhxklln.php">read more here</a>). You can see the code below.</p>
<h4>assets/js/script.js</h4>
<pre class="brush:js">$(function(){

	var note = $('#note');

	var saveTimer,
		lineHeight = parseInt(note.css('line-height')),
		minHeight = parseInt(note.css('min-height')),
		lastHeight = minHeight,
		newHeight = 0,
		newLines = 0;

	var countLinesRegex = new RegExp('\n','g');

	// The input event is triggered on key press-es,
	// cut/paste and even on undo/redo.

	note.on('input',function(e){

		// Clearing the timeout prevents
		// saving on every key press
		clearTimeout(saveTimer);
		saveTimer = setTimeout(ajaxSaveNote, 2000);

		// Count the number of new lines
		newLines = note.val().match(countLinesRegex);

		if(!newLines){
			newLines = [];
		}

		// Increase the height of the note (if needed)
		newHeight = Math.max((newLines.length + 1)*lineHeight, minHeight);

		// This will increase/decrease the height only once per change
		if(newHeight != lastHeight){
			note.height(newHeight);
			lastHeight = newHeight;
		}
	}).trigger('input');	// This line will resize the note on page load

	function ajaxSaveNote(){

		// Trigger an AJAX POST request to save the note
		$.post('index.php', { 'note' : note.val() });
	}

});</pre>
<p>Another useful thing that the above code does, is to count the number of new lines in the text and to enlarge the textarea automatically, depending on the value of the <em>line-height</em> CSS property.</p>
<p>And here is the CSS.</p>
<h3>The CSS</h3>
<p>In this section we will style the three elements you see in the HTML part of the tutorial. Each of the three elements you see there, are styled and added a background image. For the bottom part of the notepad, I am using an <strong>:after</strong> element. When the textarea is resized by jQuery, the bottom part is automatically pushed down.</p>
<h4>assets/css/styles.css</h4>
<pre class="brush:css">#pad{
	position:relative;
	width: 374px;
	margin: 180px auto 40px;
}

#note{
	font: normal 15px 'Courgette', cursive;
	line-height: 17px;
	color:#444;
	background: url('../img/mid.png') repeat-y;
	display: block;
	border: none;
	width: 329px;
	min-height: 170px;
	overflow: hidden;
	resize: none;
	outline: 0px;
	padding: 0 10px 0 35px;
}

#pad h2{
	background: url('../img/header.png') no-repeat;
	overflow: hidden;
	text-indent: -9999px;
	height: 69px;
	position: relative;
}

#pad:after{
	position:absolute;
	content:'';
	background:url('../img/footer.png') no-repeat;
	width:100%;
	height:40px;
}</pre>
<p>In addition, I have included the <a href="http://www.google.com/webfonts/specimen/Courgette" target="_blank">Courgette</a> font from Google Web Fonts, which you can see referred in the <strong>#note</strong> block.</p>
<h3>Done!</h3>
<p>I hope that you liked this simple example and are full of ideas for improvements. If you need to support older IE versions that don&#8217;t have the <em>input</em> event, I suggest you change the code so that the AJAX request is sent automatically with a timeout every 5 or 10 seconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>FrameWarp &#8211; jQuery plugin for displaying pages in a neat overlay</title>
		<link>http://tutorialzine.com/2012/07/framewarp-jquery-plugin/</link>
		<comments>http://tutorialzine.com/2012/07/framewarp-jquery-plugin/#comments</comments>
		<pubDate>Thu, 19 Jul 2012 17:31:02 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=2339</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/07/framewarp-jquery-plugin/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/07/2339-620x340.jpg" class="attachment-tzmedium" alt="FrameWarp - jQuery plugin for displaying pages in a neat overlay" /></a></div> In this tutorial we will be creating a plugin for showing pages of your site as dialog windows.]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/07/framewarp-jquery-plugin/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/07/2339-620x340.jpg" class="attachment-tzmedium" alt="FrameWarp - jQuery plugin for displaying pages in a neat overlay" /></a></div> <p>While working on an exciting new web app, I found that I needed a way to show certain pages in an overlay window. This comes handy if you want to reuse something like a sharing or a settings page in different screens of your app. Instead of hacking together something that barely got the job done, I decided to take the time, do it properly and share you with you.</p>
<p>Of course, there is the option of using one of the numerous lightbox plugins to do this, but the plugin we will be creating in this tutorial has a lot of advantages over a generic lightbox script:</p>
<ul>
<li>Lightweight &#8211; it is created specifically for showing pages, not images;</li>
<li>No UI, so the page feels like a dialog window;</li>
<li>The page can close itself, and can also send messages to the parent window;</li>
<li>Can optionally use a cache for faster subsequent page loads;</li>
<li>Uses a neat CSS animation with a JavaScript fallback.</li>
</ul>
<p>Great! Now let&#8217;s get started.</p>
<h3>The Idea</h3>
<p>When a link or button is clicked, our plugin, dubbed FrameWarp, will detect the coordinates of that element, and trigger a CSS animation of an expanding polygon moving to the center of the window. The plugin will then load an Iframe pointing to the URL we want to show. If the page is from the same origin as the current site, FrameWarp will also add two useful methods to the iframe &#8211; one for hiding it, and another one for sending a message to the parent.</p>
<p>We will be using the <a href="http://jquerypp.com/#animate" target="_blank">jQuery++ collection</a> of tools for jQuery, which converts the library&#8217;s animate() method to use CSS3 transitions on browsers that support them. This makes constructing complex CSS animations quite easy.</p>
<h3>The Animation</h3>
<p>As they say, a fiddle is worth 1000 words. So here is the animation in action (hit the <strong><em>Result</em></strong> tab):</p>
<p><iframe style="width: 100%; height: 280px;" src="http://jsfiddle.net/martinaglv/r2YLq/embedded/" frameborder="0" width="320" height="240"></iframe></p>
<p>The trick here is that we are animating the border properties of the element and the width, while the height remains 0. The left and right borders are set to transparent in the CSS of the plugin. Alternatively, you could do it with 3D CSS transforms, but it wouldn&#8217;t work in older browsers.</p>
<h3>The Plugin</h3>
<p>Now to write the plugin. We are going to wrap our code in an anonymous function so that it is isolated from the rest of the page. In effect all the variables and helper functions you can see below are private and accessible only to our plugin.</p>
<h4>assets/framewarp/framewarp.js</h4>
<pre class="brush:js">(function($){

	// Private varialble deffinitions

	var body = $('body'),
		win = $(window),
		popup, popupBG;

	var frameCache = {};
	var frameCacheDiv = $('&lt;div class="frameCacheDiv"&gt;').appendTo('body');
	var currentIframe;

	$.fn.frameWarp = function(settings){

		// The main code of the plugin will go here

	};

	// Helper Functions

	function hide(){

		// Here we will remove the popup and dark background from the page

	}

	function setUpAPI(iframe, settings){

		// In this function, we will make two API methods available to the frame,
		// if it the page is from the same domain.
	}

	function sameOrigin(url){

		// Here we will determine whether the page is from the same domain
	}

	function getOrigin(url){

		// A helper function for generating an origin string
		// of the type: https://www.google.com
		// This includes the protocol and host.
	}

})(jQuery);</pre>
<p>The plugin creates a div with a frameCacheDiv class name. It is going to hold the iframes we are adding to the page. Two more divs are added to the page by the plugin &#8211; .popup and .popupBG, which we will discuss in a moment. Now let&#8217;s inspect the helper functions.</p>
<pre class="brush:js">function hide(){

	if(currentIframe){
		currentIframe.hide();
		currentIframe = null;
	}

	popupBG.remove();
	popup.remove();
}

function setUpAPI(iframe, settings){

	if(sameOrigin(settings.url)){

		// Exposing a minimal API to the iframe
		iframe[0].contentWindow.frameWarp = {
			hide: hide,
			sendMessage:function(param){
				return settings.onMessage(param);
			}
		};
	}
}

function sameOrigin(url){

	// Compare whether the url belongs to the
	// local site or is remote

	return (getOrigin(url) == getOrigin(location.href));
}

function getOrigin(url){

	// Using an anchor element to
	// parse the URL

	var a = document.createElement('a');
	a.href = url;

	return a.protocol+'//'+a.hostname;
}</pre>
<p>Browsers implement a security feature called &#8220;same origin policy&#8221; that limits a web site from accessing the DOM of another. For this reason, we have a helper function that compares the URL of the iframe with the address of the current page. Only when both the domain and the protocol match, will the plugin attempt to access the DOM of the iframe and add the API methods for sending messages and hiding.</p>
<p>Now we are ready to write the actual frameWarp plugin! </p>
<pre class="brush:js">$.fn.frameWarp = function(settings){

	// Supplying default settings

	settings = $.extend({
		cache: true,
		url: '',
		width:600,
		height:500,
		closeOnBackgroundClick: true,
		onMessage:function(){},
		onShow:function(){}
	}, settings);

	this.on('click',function(e){

		e.preventDefault();

		var elem = $(this),
			offset = elem.offset();

		// The center of the button
		var buttonCenter = {
			x: offset.left - win.scrollLeft() + elem.outerWidth()/2,
			y: offset.top - win.scrollTop() + elem.outerHeight()/2
		};

		// The center of the window
		var windowCenter = {
			x: win.width()/2,
			y: win.height()/2
		};

		// If no URL is specified, use the href attribute.
		// This is useful for progressively enhancing links.

		if(!settings.url &amp;&amp; elem.attr('href')){
			settings.url = elem.attr('href');
		}

		// The dark background

		popupBG = $('&lt;div&gt;',{'class':'popupBG'}).appendTo(body);

		popupBG.click(function(){

			if(settings.closeOnBackgroundClick){
				hide();
			}

		}).animate({	// jQuery++ CSS3 animation
			'opacity':1
		},400);

		// The popup

		popup = $('&lt;div&gt;').addClass('popup').css({
			width	: 0,
			height	: 0,
			top		: buttonCenter.y,
			left	: buttonCenter.x - 35
		});

		// Append it to the page, and trigger a CSS3 animation
		popup.appendTo(body).animate({
			'width'					: settings.width,
			'top'					: windowCenter.y - settings.height/2,
			'left'					: windowCenter.x - settings.width/2,
			'border-top-width'		: settings.height,
			'border-right-width'	: 0,
			'border-left-width'		: 0
		},200,function(){

			popup.addClass('loading').css({
				'width': settings.width,
				'height': settings.height
			});

			var iframe;

			// If this iframe already exists in the cache
			if(settings.cache &amp;&amp; settings.url in frameCache){
				iframe = frameCache[settings.url].show();
			}
			else{

				iframe = $('&lt;iframe&gt;',{
					'src' : settings.url,
					'css' : {
						'width' : settings.width,
						'height' : settings.height,
					}
				});

				// If the cache is enabled, add the frame to it
				if(settings.cache){
					frameCache[settings.url] = iframe;
					iframe.data('cached',true);
					settings.onShow();
				}
				else{

					// remove non-cached iframes
					frameCacheDiv.find('iframe').each(function(){
						var f = $(this);
						if(!f.data('cached')){
							f.remove();
						}
					});
				}

				iframe.ready(function(){
					frameCacheDiv.append(iframe);
					setUpAPI(iframe, settings);
					settings.onShow();
				});
			}

			currentIframe = iframe;

		});

	});

	return this;
};</pre>
<p>As I mentioned in the opening section, we are using <a href="http://tutorialzine.com/2012/06/jquery-is-a-collection-of-power-tools-for-jquery/" title="jQuery++ is a Collection of Power Tools for jQuery">jQuery++</a> to enhance jQuery&#8217;s animate() function to support CSS3 animations. This way we don&#8217;t have to write tons of CSS, and we also achieve full backwards compatibility, as the new animate() method will fall back to the old if the browser has not support for CSS animations.</p>
<p>Once the first animation is complete, we add the loading class to the .popup div. The new class adds an animated preloader gif to the popup and a soft box-shadow, as you can see by inspecting <b>assets/framewarp/framewarp.css</b>.</p>
<div id="attachment_2346" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com.localhost/2012/07/framewarp-jquery-plugin/"><img src="http://cdn.tutorialzine.com/wp-content/uploads/2012/07/framewarp-jquery-plugin.jpg" alt="FrameWarp jQuery Plugin" title="FrameWarp jQuery Plugin" width="620" height="300" class="size-full wp-image-2346" /></a><p class="wp-caption-text">FrameWarp jQuery Plugin</p></div>
<h3>Using the plugin</h3>
<p>To use the plugin, include <b>assets/framewarp/framewarp.css</b> to the head of your page, and <b>assets/framewarp/framewarp.js</b> after your copy of the jQuery library.</p>
<p>After this, all that is left is to initialize the plugin. As an example, here is the code that drives our demo page:</p>
<h4>assets/js/script.s</h4>
<pre class="brush:js">$(function(){

	// If no url property is passed, the
	// href attribute will be used

	$('#b1').frameWarp();

	$('#b2').frameWarp({
		onMessage: function(msg){
			$('#messages').append('<strong>Message Received:</strong> '+ msg+'
');
		}
	});

	// Cache is enabled by default
	$('#b3').frameWarp({
		url : 'http://www.cnn.com/'
	});

	// Disable caching
	$('#b4').frameWarp({
		url : 'http://www.cnn.com/',
		cache:false
	});
});</pre>
<h3>Done!</h3>
<p>With this the plugin is complete! You can use it to enhance your web app and reuse certain parts of it without writing extra code. I would love to hear your suggestions or thoughts in the comment section below. </p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/07/framewarp-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Have You Heard About CSS Filters Yet?</title>
		<link>http://tutorialzine.com/2012/06/quick-tip-css-filters/</link>
		<comments>http://tutorialzine.com/2012/06/quick-tip-css-filters/#comments</comments>
		<pubDate>Wed, 27 Jun 2012 11:03:21 +0000</pubDate>
		<dc:creator>Jonathan Simpson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Filters]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=2279</guid>
		<description><![CDATA[Over the years CSS has been providing us with more and more ways to accomplish things without an image editor, whether it be 3D transforms or border radius. Here are a few more awesome techniques with CSS filters!]]></description>
				<content:encoded><![CDATA[<p>Over the years CSS has been providing us with more and more ways to accomplish things without an image editor, whether it be 3D transforms or border radius. One of the missing pieces to this puzzle, though, is the ability to saturate, blur, or otherwise filter a photograph with just CSS.</p>
<p>To solve this problem, the W3C has come up with <strong>CSS Filters</strong>. Using filters we can accomplish many effects which are applicable not only to images, but text and HTML too!</p>
<h3>Filter Support</h3>
<p>The CSS filter property works just like any other CSS property. However, as usual browser support is pretty thin on the ground. <strong>The only browsers that support filters are webkit based (Safari and Chrome)</strong>. For this reason we need to use <strong>browser prefixes</strong>. Although webkit is the only engine to support filters, we will use all browser prefixes as it is best practice.</p>
<h3>Using Filters</h3>
<p>There are a variety of values you can use. When using filters remember that not all your visitors will be able to see them, so it’s best not to use them in a way that is necessary to the user experience. Here’s an example, in which we set an image to have a 5px Gaussian blur:</p>
<pre class="brush:css">img {
	-webkit-filter: blur(5px);
	-moz-filter: blur(5px);
	-ms-filter: blur(5px);
	-o-filter: blur(5px);
	filter: blur(5px);
}</pre>
<div id="attachment_2280" class="wp-caption alignnone" style="width: 630px"><img class="size-full wp-image-2280 " title="CSS Gaussian Blur" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/06/1.jpg" alt="CSS Gaussian Blur" width="620" height="360" /><p class="wp-caption-text">CSS Gaussian Blur</p></div>
<p>Filters have much wider usages though, another example is using filters to grayscale an image:</p>
<pre class="brush:css">img {
	-webkit-filter: grayscale(100%);
	-moz-filter: grayscale(100%);
	-ms-filter: grayscale(100%);
	-o-filter: grayscale(100%);
	filter: grayscale(100%);
}</pre>
<div id="attachment_2281" class="wp-caption alignnone" style="width: 630px"><img class="size-full wp-image-2281 " title="CSS Grayscale" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/06/2.jpg" alt="CSS Grayscale" width="620" height="360" /><p class="wp-caption-text">CSS Grayscale</p></div>
<p>Pretty simple, huh? Grayscale and blur are only two of a huge range of filters. If you want to learn more you can check out a more comprehensive <a href="http://www.inserthtml.com/2012/06/css-filters/">list of filters here</a>. Why not experiment a little?</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/06/quick-tip-css-filters/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Tutorial: Create a Beautiful Password Strength Meter</title>
		<link>http://tutorialzine.com/2012/06/beautiful-password-strength-indicator/</link>
		<comments>http://tutorialzine.com/2012/06/beautiful-password-strength-indicator/#comments</comments>
		<pubDate>Mon, 11 Jun 2012 09:55:06 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=2216</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/06/beautiful-password-strength-indicator/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/06/2216-620x340.jpg" class="attachment-tzmedium" alt="Tutorial: Create a Beautiful Password Strength Meter" /></a></div> In this tutorial we will be creating a beautiful password strength indicator. It will determine the complexity of a password and move a meter accordingly for an eye catching effect.]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/06/beautiful-password-strength-indicator/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/06/2216-620x340.jpg" class="attachment-tzmedium" alt="Tutorial: Create a Beautiful Password Strength Meter" /></a></div> <p>In this tutorial we will be creating a beautiful password strength indicator. It will determine the complexity of a password and move a meter accordingly with the help of the new <a href="http://danpalmer.me/jquery-complexify" target="_blank">Complexify jQuery plugin</a>. Only when a sufficiently complex password is entered, will the user be able to continue with their registration.</p>
<p>A <a href="http://cdn.tutorialzine.com/psd/password_meter.zip">PSD file is also available</a>, so you can customize the form to your liking.</p>
<h3>The HTML</h3>
<p>We start off with a standard HTML5 document that will include our registration form. The form will only serve as an example of the password meter &#8211; if you need support for actual registrations, you will need to write the required server-side code.</p>
<h4>index.html</h4>
<pre class="brush:html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;How to Make a Beautiful Password Strength Indicator&lt;/title&gt;

        &lt;!-- The stylesheet --&gt;
        &lt;link rel="stylesheet" href="assets/css/styles.css" /&gt;

        &lt;!--[if lt IE 9]&gt;
          &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
        &lt;![endif]--&gt;
    &lt;/head&gt;

    &lt;body&gt;

        &lt;div id="main"&gt;

        	&lt;h1&gt;Sign up, it's FREE!&lt;/h1&gt;

        	&lt;form class="" method="post" action=""&gt;

        		&lt;div class="row email"&gt;
	    			&lt;input type="text" id="email" name="email" placeholder="Email" /&gt;
        		&lt;/div&gt;

        		&lt;div class="row pass"&gt;
        			&lt;input type="password" id="password1" name="password1" placeholder="Password" /&gt;
        		&lt;/div&gt;

        		&lt;div class="row pass"&gt;
        			&lt;input type="password" id="password2" name="password2" placeholder="Password (repeat)" disabled="true" /&gt;
        		&lt;/div&gt;

        		&lt;!-- The rotating arrow --&gt;
        		&lt;div class="arrowCap"&gt;&lt;/div&gt;
        		&lt;div class="arrow"&gt;&lt;/div&gt;

        		&lt;p class="meterText"&gt;Password Meter&lt;/p&gt;

        		&lt;input type="submit" value="Register" /&gt;

        	&lt;/form&gt;
        &lt;/div&gt;

        &lt;!-- JavaScript includes - jQuery, the complexify plugin and our own script.js --&gt;
		&lt;script src="http://code.jquery.com/jquery-1.7.2.min.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/jquery.complexify.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/script.js"&gt;&lt;/script&gt;

    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>We are including the latest version of jQuery, the Complexify plugin and our script.js right before the closing body tag for better performance.</p>
<div id="attachment_2224" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/06/beautiful-password-strength-indicator/"><img class="size-full wp-image-2224" title="Password Strength Meter" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/06/password-strength-css3.jpg" alt="Password Strength Meter" width="620" height="460" /></a><p class="wp-caption-text">Password Strength Meter</p></div>
<h3>jQuery</h3>
<p>The jQuery code below is quite straightforward. We are binding a number of events to the form elements and validating them. If an error was encountered, we add an &#8220;<em>error</em>&#8221; class to the <strong>.row</strong> div that contains the input. This will display the red cross. The &#8220;<em>success</em>&#8221; class on the other hand will display a green check mark. When the form is submitted, we check whether all of the rows are marked as successful for allowing the submission.</p>
<h4>assets/js/script.js</h4>
<pre class="brush:js">$(function(){

	// Form items
	var pass1 = $('#password1'),
		pass2 = $('#password2'),
		email = $('#email'),
		form = $('#main form'),
		arrow = $('#main .arrow');

	// Empty the fields on load
	$('#main .row input').val('');

	// Handle form submissions
	form.on('submit',function(e){

		// Is everything entered correctly?
		if($('#main .row.success').length == $('#main .row').length){

			// Yes!
			alert("Thank you for trying out this demo!");
			e.preventDefault(); // Remove this to allow actual submission

		}
		else{

			// No. Prevent form submission
			e.preventDefault();

		}
	});

	// Validate the email field
	email.on('blur',function(){

		// Very simple email validation
		if (!/^\S+@\S+\.\S+$/.test(email.val())){
			email.parent().addClass('error').removeClass('success');
		}
		else{
			email.parent().removeClass('error').addClass('success');
		}

	});

	/* The Complexify code will go here */

	// Validate the second password field
	pass2.on('keydown input',function(){

		// Make sure it equals the first
		if(pass2.val() == pass1.val()){

			pass2.parent()
					.removeClass('error')
					.addClass('success');
		}
		else{
			pass2.parent()
					.removeClass('success')
					.addClass('error');
		}
	});

});</pre>
<p>With this out of the way, we can move on with the Complexify plugin that will validate the password. The plugin takes a callback function with two arguments &#8211; a percentage value from 0 to 100 depending on the complexity of the password, and a <strong>valid</strong> flag that takes into account the minimum length requirement, defined by the <strong>minimumChars</strong> property.</p>
<p>By tweaking the <strong>strengthScaleFactor</strong> property you can allow simpler passwords to be used. The default scale is 1 which requires a mix of upper and lower case letters, numbers and special characters, but I found it too strict so I lowered it to 0.7. You can lower it further if you need even simpler passwords.</p>
<pre class="brush:js">pass1.complexify({minimumChars:6, strengthScaleFactor:0.7}, function(valid, complexity){

	if(valid){
		pass2.removeAttr('disabled');

		pass1.parent()
				.removeClass('error')
				.addClass('success');
	}
	else{
		pass2.attr('disabled','true');

		pass1.parent()
				.removeClass('success')
				.addClass('error');
	}

	var calculated = (complexity/100)*268 - 134;
	var prop = 'rotate('+(calculated)+'deg)';

	// Rotate the arrow. Additional rules for different browser engines.
	arrow.css({
		'-moz-transform':prop,
		'-webkit-transform':prop,
		'-o-transform':prop,
		'-ms-transform':prop,
		'transform':prop
	});
});</pre>
<p>If a valid value has been passed, we will enable the second password field (it is disabled by default). We will also use CSS3 transformations to rotate the arrow. The transformation will be animated thanks to a transition property which you can see in the CSS section. The arrow moves from -134 to 134 degrees (the default 0 degrees correspond to the arrow pointing vertically up), so the code compensates for that.</p>
<h3>CSS</h3>
<p>I will include only the more interesting parts of the stylesheet here. The code that follows styles the arrow and defines a transition.</p>
<h4>assets/css/styles.css</h4>
<pre class="brush:css">#main form .arrow{
    background: url("../img/arrow.png") no-repeat -10px 0;
    height: 120px;
    left: 214px;
    position: absolute;
    top: 392px;
    width: 11px;

   	/* Defining a smooth CSS3 animation for turning the arrow */

    -moz-transition:0.3s;
    -webkit-transition:0.3s;
    -o-transition:0.3s;
    -ms-transition:0.3s;
    transition:0.3s;

    /* Putting the arrow in its initial position */

	-moz-transform: rotate(-134deg);
	-webkit-transform: rotate(-134deg);
	-o-transform: rotate(-134deg);
	-ms-transform: rotate(-134deg);
	transform: rotate(-134deg);
}

/* The small piece that goes over the arrow */
#main form .arrowCap{
	background: url("../img/arrow.png") no-repeat -43px 0;
	height: 20px;
	left: 208px;
	position: absolute;
	top: 443px;
	width: 20px;
	z-index: 10;
}</pre>
<p>You can find the rest of the code in <strong>assets/css/styles.css</strong>. The best way to learn how it all works is by inspecting the working demo with Firebug or Chrome&#8217;s Developer tools and playing with the styles.</p>
<h3>We&#8217;re done!</h3>
<p>You can build upon this example and use it to present an eye catching validation option for your customers. And it is even easier to customize with the included PSD.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/06/beautiful-password-strength-indicator/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Timeline Portfolio</title>
		<link>http://tutorialzine.com/2012/04/timeline-portfolio/</link>
		<comments>http://tutorialzine.com/2012/04/timeline-portfolio/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 08:16:09 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1920</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/04/timeline-portfolio/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/04/1920.jpg" class="attachment-tzmedium" alt="Timeline Portfolio" /></a></div> This time we will be using the Timeline jQuery plugin as a dark themed portfolio in which you can showcase projects and important events in your career.]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/04/timeline-portfolio/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/04/1920.jpg" class="attachment-tzmedium" alt="Timeline Portfolio" /></a></div> <p><a href="http://timeline.verite.co/" target="_blank">Timeline</a> is a jQuery plugin specialized in showing a chronological series of events. You can embed all kinds of media including tweets, videos and maps, and associate them with a date. With some design tweaks, this will make it perfect for a portfolio in which you showcase your work and interests.</p>
<h3>The HTML</h3>
<p>Timeline comes with a light colored theme by default. It is perfectly usable and in most cases would be exactly what you need. However, for our portfolio, a dark design would be a better fit, so we will customize it to our liking.</p>
<p>First, let&#8217;s look at the basic layout of the page:</p>
<h4>index.html</h4>
<pre class="brush:html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;Timeline Portfolio | Tutorialzine Demo&lt;/title&gt;

        &lt;!-- The default timeline stylesheet --&gt;
        &lt;link rel="stylesheet" href="assets/css/timeline.css" /&gt;
        &lt;!-- Our customizations to the theme --&gt;
        &lt;link rel="stylesheet" href="assets/css/styles.css" /&gt;

		&lt;!-- Google Fonts --&gt;
        &lt;link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Dancing+Script|Antic+Slab" /&gt;

        &lt;!--[if lt IE 9]&gt;
          &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
        &lt;![endif]--&gt;
    &lt;/head&gt;

    &lt;body&gt;

		&lt;div id="timeline"&gt;
			&lt;!-- Timeline will generate additional markup here --&gt;
		&lt;/div&gt;

        &lt;!-- JavaScript includes - jQuery, turn.js and our own script.js --&gt;
		&lt;script src="http://code.jquery.com/jquery-1.7.1.min.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/timeline-min.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/script.js"&gt;&lt;/script&gt;

    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>In the head section, we have the plugin&#8217;s stylesheet &#8211; timeline.css, and styles.css, which will hold our customizations. In the footer we have the jQuery library, timeline plugin and <strong>script.js</strong> which initializes it.</p>
<p>When we call the plugin, it will search for a div on your page with the ID of <strong>timeline</strong>. Inside it, it will inserts all the markup it needs to present the timeline:</p>
<pre class="brush:html">&lt;div class="container main" id="timeline"&gt;
	&lt;div class="feature slider" style="overflow-y: hidden;"&gt;
		&lt;div class="slider-container-mask slider-container slider-item-container"&gt;

			&lt;!-- The divs below are the events of the timeline --&gt;

			&lt;div class="slider-item content"&gt;
				&lt;div class="text container"&gt;

					&lt;h2 class="start"&gt;Johnny B Goode&lt;/h2&gt;
					&lt;p&gt;&lt;em&gt;&lt;span class="c1"&gt;Designer&lt;/span&gt; &amp;amp; &lt;span class=
					"c2"&gt;Developer&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;

				&lt;/div&gt;

				&lt;div class="media media-wrapper media-container"&gt;
					&lt;!-- Images or other media go here --&gt;
				&lt;/div&gt;
			&lt;/div&gt;

			&lt;div class="slider-item content content-container"&gt;
				&lt;div class="text container"&gt;

					&lt;h2 class="date"&gt;March 2009&lt;/h2&gt;
					&lt;h3&gt;My first experiment in time-lapse photography&lt;/h3&gt;
					&lt;p&gt;Nature at its finest in this video.&lt;/p&gt;

				&lt;/div&gt;

				&lt;div class="media media-wrapper media-container"&gt;
					&lt;!-- Images or other media go here --&gt;
				&lt;/div&gt;
			&lt;/div&gt;

			&lt;!-- More items go here --&gt;
		&lt;/div&gt;

        &lt;!-- Next arrow --&gt;
		&lt;div class="nav-next nav-container"&gt;
			&lt;div class="icon"&gt;&lt;/div&gt;
			&lt;div class="date"&gt;March 2010&lt;/div&gt;
			&lt;div class="title"&gt;Logo Design for a pet shop&lt;/div&gt;
		&lt;/div&gt;

        &lt;!-- Previous arrow --&gt;
		&lt;div class="nav-previous nav-container"&gt;
			&lt;div class="icon"&gt;&lt;/div&gt;
			&lt;div class="date"&gt;July 2009&lt;/div&gt;
			&lt;div class="title"&gt;Another time-lapse experiment&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;

	&lt;div class="navigation"&gt;

			&lt;!-- The navigation items go here (the tooltips in the bottom)
                one for each of the events --&gt;

			&lt;div class="time"&gt;
				&lt;!-- The timeline numbers go here --&gt;
			&lt;/div&gt;
		&lt;/div&gt;

		&lt;div class="timenav-background"&gt;
			&lt;div class="timenav-line" style="left: 633px;"&gt;&lt;/div&gt;

			&lt;div class="timenav-interval-background top-highlight"&gt;&lt;/div&gt;
		&lt;/div&gt;

		&lt;div class="toolbar" style="top: 27px;"&gt;
			&lt;div class="back-home icon" title="Return to Title"&gt;&lt;/div&gt;
			&lt;div class="zoom-in icon" title="Expand Timeline"&gt;&lt;/div&gt;
			&lt;div class="zoom-out icon" data-original-title="Contract Timeline"&gt;&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<p>As we will be modifying the CSS of the timeline, the fragment above will give you a better idea of the customizations. Note that we won&#8217;t be recreating the plugin&#8217;s stylesheet from scratch, we will only be overriding some of the rules in our own css file. This has the benefit of making future updates to the plugin straightforward, not to mention that it will be much easier.</p>
<div id="attachment_1931" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/04/timeline-portfolio/"><img class="size-full wp-image-1931" title="Timeline Portfolio with jQuery" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/03/timeline-portfolio-jquery.jpg" alt="Timeline Portfolio with jQuery" width="620" height="460" /></a><p class="wp-caption-text">Timeline Portfolio with jQuery</p></div>
<p>Writing the CSS by looking at the markup alone would be a tough undertaking, given that our rules must have <a href="http://css-tricks.com/specifics-on-css-specificity/" target="_blank">precedence</a> over the ones used in <em>timeline.css</em>. Fortunately, there is a much easier way, as you will see in the CSS section of this tutorial.</p>
<h3>The jQuery</h3>
<p>To initialize the plugin, we need to call the VMM.Timeline() method on document ready:</p>
<pre class="brush:js">$(function(){

	var timeline = new VMM.Timeline();
	timeline.init("data.json");

});</pre>
<p>The init method takes single argument &#8211; the data source. It can either be a json file like above, or a Google spreadsheet (reminiscent of our <a title="Dynamic FAQ Section w/ jQuery, YQL &amp; Google Docs" href="http://tutorialzine.com/2010/08/dynamic-faq-jquery-yql-google-docs/">Spredsheet Powered FAQ Tutorial</a>).</p>
<blockquote class="note"><p>For more information on the supported data sources, see the <a href="http://timeline.verite.co/#fileformat" target="_blank">documentation on the plugin&#8217;s site</a>, or browse the data.json file in the zip download for this tutorial.</p></blockquote>
<h3>The CSS</h3>
<p>I used Firebug&#8217;s HTML Inspector to get the right selectors for the elements that we are about to customize. In the HTML tab, it is easy to see what rules have been applied to each element by <em>timeline.css</em>. To override them, I copied the same selectors to <em>styles.css</em> which is where our modifications will take place. On several occurrences, however, I have used the <strong>!important</strong> flag to make my work easier.</p>
<p>All the customizations you see below override only a handful of CSS styles. The rest are inherited by the default stylesheet.<strong> Let&#8217;s begin!</strong></p>
<p>The first thing we will do in <strong>styles.css</strong>, after styling the page itself, is to change the backgrounds of the timeline:</p>
<pre class="brush:css">#timeline{
	background:none;
}

/* The individual events in the slider */
.slider .slider-container-mask .slider-container{
	background:none;
}

/* Setting a custom background image */
#timeline div.navigation{
    background: url('../img/timeline_bg.jpg') repeat;
    border-top:none;
}</pre>
<div id="attachment_1932" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/04/timeline-portfolio/"><img class="size-full wp-image-1932" title="Timeline Navigation with a CSS 3D Effect" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/03/a-css-3d-effect.jpg" alt="Timeline Navigation with a CSS 3D Effect" width="620" height="260" /></a><p class="wp-caption-text">Timeline Navigation with a CSS 3D Effect</p></div>
<p>To create the 3D effect of the timeline navigation, we will need to use additional elements. But the Timeline plugin doesn&#8217;t include such in its markup. An easy solution is to use <strong>:before</strong> / <strong>:after</strong> pseudo elements. The :after element is the darker top part and it uses a linear gradient to enhance the effect.</p>
<pre class="brush:css">#timeline div.navigation:before{
	position:absolute;
	content:'';
	height:40px;
	width:100%;
	left:0;
	top:-40px;
	background: url('../img/timeline_bg.jpg') repeat;
}

#timeline div.navigation:after{
	position:absolute;
	content:'';
	height:10px;
	width:100%;
	left:0;
	top:-40px;
	background:repeat-x;

	background-image: linear-gradient(bottom, #434446 0%, #363839 100%);
	background-image: -o-linear-gradient(bottom, #434446 0%, #363839 100%);
	background-image: -moz-linear-gradient(bottom, #434446 0%, #363839 100%);
	background-image: -webkit-linear-gradient(bottom, #434446 0%, #363839 100%);
	background-image: -ms-linear-gradient(bottom, #434446 0%, #363839 100%);
}</pre>
<p>Then we add a dark background to the timeline navigation (the section with the small clickable tooltips that represent the events):</p>
<pre class="brush:css">#timeline div.timenav-background{
 	background-color:rgba(0,0,0,0.4) !important;

}

#timeline .navigation .timenav-background .timenav-interval-background{
	background:none;
}

#timeline .top-highlight{
	background-color:transparent !important;
}</pre>
<p>Later we style the zoom-in / zoom-out buttons and toolbar:</p>
<pre class="brush:css">#timeline .toolbar{
	border:none !important;
	background-color: #202222 !important;
}

#timeline .toolbar div{
	border:none !important;
}</pre>
<p>The numeric scale at the bottom comes next:</p>
<pre class="brush:css">#timeline .navigation .timenav .time .time-interval-minor .minor{
	margin-left:-1px;
}

#timeline .navigation .timenav .time .time-interval div{
	color: #CCCCCC;
}</pre>
<p>The previous and next arrows:</p>
<pre class="brush:css">.slider .nav-previous .icon {
	background: url("timeline.png") no-repeat scroll 0 -293px transparent;
}

.slider .nav-previous,.slider .nav-next{
	font-family:'Segoe UI',sans-serif;
}

.slider .nav-next .icon {
	background: url("timeline.png") no-repeat scroll 72px -221px transparent;
	width: 70px !important;
}

.slider .nav-next:hover .icon{
	position:relative;
	right:-5px;
}

.slider .nav-previous:hover, .slider .nav-next:hover {
    color: #666;
    cursor: pointer;
}

#timeline .thumbnail {
	border: medium none;
}</pre>
<p>The loading screen:</p>
<pre class="brush:css">#timeline .feedback {
	background-color: #222222;
	box-shadow: 0 0 30px rgba(0, 0, 0, 0.2) inset;
	border:none;
}

#timeline .feedback div{
	color: #AAAAAA;
	font-size: 14px !important;
	font-weight: normal;
}</pre>
<p>Then we move on to the slides:</p>
<pre class="brush:css">#timeline .slider-item h2,
#timeline .slider-item h3{
	font-family:'Antic Slab','Segoe UI',sans-serif;
}

#timeline .slider-item h2{
	color:#fff;
}

#timeline .slider-item p{
	font-family:'Segoe UI',sans-serif;
}

#timeline .slider-item img,
#timeline .slider-item iframe{
	border:none;
}</pre>
<p>Finally, we will customize the appearance of the front page. I am using <strong>nth-child(1)</strong> to target only the first slider-item, which contains the name and description of the timeline which have been defined in the JSON data source.</p>
<pre class="brush:css">/* Customizing the first slide - the cover */

#timeline .slider-item:nth-child(1) h2{
	font:normal 70px/1 'Antic Slab','Segoe UI',sans-serif;
	background:rgba(0,0,0,0.3);
	white-space: nowrap;
	padding:10px 5px 5px 20px;
	position:relative;
	right:-60px;
	z-index:10;
}

#timeline .slider-item:nth-child(1) p i{
	font:normal normal 40px 'Dancing Script','Segoe UI',sans-serif;
	background:rgba(0,0,0,0.3);
	white-space: nowrap;
	padding:5px 20px;
	position:relative;
	right:-60px;
	z-index:10;
}

#timeline .slider-item:nth-child(1) p .c1{
	color:#1bdff0;
}

#timeline .slider-item:nth-child(1) p .c2{
	color:#c92fe6;
}

#timeline .slider-item:nth-child(1) .media-container {
	left: -30px;
	position: relative;
	z-index: 1;
}

#timeline .slider-item:nth-child(1) .credit{
	text-align: center;
}</pre>
<p>The only thing left is to open up <em>timeline.psd</em> that is bundled with the download of the plugin, and change the color of some of the icons in photoshop. I have included the necessary files in the zip download for this tutorial. With this our timeline portfolio is complete!</p>
<h3>Done!</h3>
<p>You can use this portfolio to display not only your recent projects, but also interests and important moments of your career. Share your thoughts and suggestions in the comment section.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/04/timeline-portfolio/feed/</wfw:commentRss>
		<slash:comments>176</slash:comments>
		</item>
		<item>
		<title>Making a Page Flip Magazine with turn.js</title>
		<link>http://tutorialzine.com/2012/03/instagram-magazine-php-jquery/</link>
		<comments>http://tutorialzine.com/2012/03/instagram-magazine-php-jquery/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 19:02:32 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1889</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/03/instagram-magazine-php-jquery/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/03/1889.jpg" class="attachment-tzmedium" alt="Making a Page Flip Magazine with turn.js" /></a></div> In this tutorial we are going to use PHP and the turn.js plugin, an implementation of the page flip effect with pure CSS3 and jQuery, to build an Instagram powered magazine.]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/03/instagram-magazine-php-jquery/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/03/1889.jpg" class="attachment-tzmedium" alt="Making a Page Flip Magazine with turn.js" /></a></div> <p>The page flip effect used to be the quintessential Flash animation. On the web, it has powered everything from magazines to presentations, with its popularity declining over time, only to be reinvented on mobile devices as ebook reading apps.</p>
<p>In this tutorial we are going to use PHP and the <a href="http://www.turnjs.com/" target="_blank">turn.js plugin</a>, an implementation of the page flip effect with pure CSS3 and jQuery, to build a pretty magazine. We will fetch the most popular images from <a href="http://instagram.com/" target="_blank">Instagram</a> every hour, and use them as pages.</p>
<h3>HTML</h3>
<p>First we need to lay down the foundations of today&#8217;s example. We will use a single page design, which combines HTML5 markup and PHP in the same file for greater simplicity. You can see the resulting layout below:</p>
<h4>index.php</h4>
<pre class="brush:html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;Making an Instagram Magazine | Tutorialzine Demo&lt;/title&gt;

        &lt;!-- Our Stylesheet --&gt;
        &lt;link rel="stylesheet" href="assets/css/styles.css" /&gt;

        &lt;!--[if lt IE 9]&gt;
          &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
        &lt;![endif]--&gt;
    &lt;/head&gt;

    &lt;body&gt;

		&lt;div id="magazine" class="centerStart"&gt;

		&lt;!-- PHP will go here --&gt;

		&lt;/div&gt;

        &lt;!-- JavaScript includes - jQuery, turn.js and our own script.js --&gt;
		&lt;script src="http://code.jquery.com/jquery-1.7.1.min.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/turn.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/script.js"&gt;&lt;/script&gt;

    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>We include <em>styles.css</em> in the head, and our JavaScript files at the bottom. The latter are the jQuery library, the turn.js plugin and script.js, where we will be initializing the plugin and listening for keyboard events. The PHP code that we will be writing in the next section will go in the <em>#magazine</em> div. PHP will have the job of generating the pages of our magazine, which will be used by turn.js.</p>
<p>As an example, here is the markup of the first three pages of the magazine:</p>
<h4>Generated code</h4>
<pre class="brush:html">&lt;div id="page1" class="page"&gt;
	&lt;div class="img1"&gt;

		&lt;!-- The pageNum span can be either on the left,
				or the right if the page is odd/even. --&gt;

		&lt;span class="pageNum right"&gt;1 // 32&lt;/span&gt;
		&lt;img src="assets/img/cover.jpg" alt="Cover" /&gt;
	&lt;/div&gt;
&lt;/div&gt;

&lt;div id="page2" class="page"&gt;
	&lt;div class="img2"&gt;
		&lt;span class="pageNum left"&gt;2 // 32&lt;/span&gt;
		&lt;img src="http://distilleryimage7.instagram.com/..." alt="Little tulips" /&gt;
	&lt;/div&gt;
&lt;/div&gt;

&lt;div id="page3" class="page"&gt;
	&lt;div class="img3"&gt;
		&lt;span class="pageNum right"&gt;3 // 32&lt;/span&gt;
		&lt;img src="http://distilleryimage2.instagram.com/..." alt="My style" /&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<p>The divs you see above are direct descendants of the #magazine div. This is the only requirement imposed by turn.js. You don&#8217;t need to have any special classes or data attributes for the elements to be interpreted as pages. With this we are ready to move on with the PHP code!</p>
<div id="attachment_1898" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/03/instagram-magazine-php-jquery/"><img class="size-full wp-image-1898" title="Page Flip Magazine with CSS3 and jQuery" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/03/instagram-page-flip-magazine-jquery-php.jpg" alt="Page Flip Magazine with CSS3 and jQuery" width="620" height="460" /></a><p class="wp-caption-text">Page Flip Magazine with CSS3 and jQuery</p></div>
<h3>PHP</h3>
<p>PHP will have the task of communicating with Instagram&#8217;s API, caching the results, and generating the markup you saw above.</p>
<p>The first step is to register at the <a href="http://instagram.com/developer/" target="_blank">Instagram developer</a> website. After you obtain your <strong>client_id</strong> key, place it in <em><strong>index.php</strong></em> as the value of <code>$instagramClientID</code>. We won&#8217;t be needing any of the advanced functionality of the API, we will only be requesting the most popular images. This frees us from having to implement OAuth authentication, which would make today&#8217;s example significantly more complex.</p>
<blockquote class="note"><p>Note that if you want to modify the magazine and show photos other than the most popular, say your latest images, you will need to implement OAuth and authenticate your app to have access to your photos. <a href="http://instagr.am/developer/auth/" target="_blank">Consult the docs</a> for further information.</p></blockquote>
<p>Here is an example JSON response of the currently popular images on Instagram. I have omitted some of the attributes to make the code easier to read.</p>
<h4>Popular images JSON response</h4>
<pre class="brush:js">{    "meta": {
        "code": 200
    },
    "data": [{
        "tags": ["beautiful", "sky"],
        "location": "null",
        "comments": {
            "count": 31,
            "data": [...]
        },
        "filter": "Normal",
        "created_time": "1331910134",
        "link": "http:\/\/instagr.am\/p\/IPNNknqs84\/",
        "likes": {
            "count": 391,
            "data": [..]
        },
        "images": {
            "low_resolution": {
                "url": "http:\/\/distilleryimage8.instagram.com\/03c80dd86f7911e1a87612313804ec91_6.jpg",
                "width": 306,
                "height": 306
            },
            "thumbnail": {
                "url": "http:\/\/distilleryimage8.instagram.com\/03c80dd86f7911e1a87612313804ec91_5.jpg",
                "width": 150,
                "height": 150
            },
            "standard_resolution": {
                "url": "http:\/\/distilleryimage8.instagram.com\/03c80dd86f7911e1a87612313804ec91_7.jpg",
                "width": 612,
                "height": 612
            }
        },
        "caption": {
            "created_time": "1331910148",
            "text": "Goodnight.\ue056",
            "from": {
                "username": "jent99",
                "profile_picture": "http:\/\/images.instagram.com\/profiles\/profile_6227738_75sq_1319878922.jpg",
                "id": "6227738",
                "full_name": "jent99"
            },
            "id": "148395540733414783"
        },
        "type": "image",
        "id": "148395420004568888_6227738",
        "user": {
            "username": "jent99",
            "website": "",
            "bio": "Mostly nature pics.\ue32b\ue32b\ue32b Hope you like them.\ue056\ue32a     \ue334gi\ue334                    ",
            "profile_picture": "http:\/\/images.instagram.com\/profiles\/profile_6227738_75sq_1319878922.jpg",
            "full_name": "jent99",
            "id": "6227738"
        }
    }, {
		/* More photos here*/
	}]
}</pre>
<p>The API is limited to returning only 32 pics, but this is plenty for our example. You can see that each photo has three image sizes, but we will only be needing the standard one. There is also various other information that you can use like caption, dimensions, tags, comments, and more.</p>
<p>PHP will cache the results of this API call so we hit Instagram&#8217;s servers only once per hour. This will make our application more responsive and limit the number of calls.</p>
<h4>index.php</h4>
<pre class="brush:php">// You can obtain this client ID from the Instagram API page
$instagramClientID = '-- place your client id key here --';

$api = 'https://api.instagram.com/v1/media/popular?client_id='.$instagramClientID;
$cache = 'cache.txt';

if(file_exists($cache) &amp;&amp; filemtime($cache) &gt; time() - 60*60){
	// If a cache file exists, and it is
	// fresher than 1 hour, use it
	$images = unserialize(file_get_contents($cache));
}
else{
	// Make an API request and create the cache file

	// Fetch the 32 most popular images on Instagram
	$response = file_get_contents($api);

	$images = array();

	// Decode the response and build an array
	foreach(json_decode($response)-&gt;data as $item){

		$title = '';

		if($item-&gt;caption){
			$title = mb_substr($item-&gt;caption-&gt;text,0,70,"utf8");
		}

		$src = $item-&gt;images-&gt;standard_resolution-&gt;url;

		$images[] = array(
			"title" =&gt; htmlspecialchars($title),
			"src" =&gt; htmlspecialchars($src)
		);
	}

	// Remove the last item, so we still have
	// 32 items when when the cover is added
	array_pop($images);

	// Push the cover in the beginning of the array
	array_unshift($images,array("title"=&gt;"Cover", "src"=&gt;"assets/img/cover.jpg"));

	// Update the cache file
	file_put_contents($cache,serialize($images));
}

# Generate the markup
$totalPages = count($images);
foreach($images as $i=&gt;$image){

	?&gt;

	&lt;div id="page&lt;?php echo $i+1?&gt;" class="page"&gt;
		&lt;div class="img&lt;?php echo $i+1?&gt;"&gt;
			&lt;span class="pageNum &lt;?php echo ($i+1)%2? 'right' : 'left'?&gt;"&gt;&lt;?php echo $i+1?&gt; // &lt;?php echo $totalPages?&gt;&lt;/span&gt;
			&lt;img src="&lt;?php echo $image['src']?&gt;" alt="&lt;?php echo $image['title']?&gt;" /&gt;
		&lt;/div&gt;
	&lt;/div&gt;

	&lt;?php

}</pre>
<p>Caching is straightforward: we are using a temporary file &#8211; <em>cache.txt</em> &#8211; to store a serialized representation of the image array. If the cache file is non-existing or is older than an hour, we issue a new API request.</p>
<p>Notice the calls to <em><strong>array_pop</strong></em> and <em><strong>array_unshift</strong></em>. These are necessary as to make room for the custom cover image that is stored in <span style="text-decoration: underline;"><em>assets/img</em></span>. The magazine works best if we have an even number of pages, otherwise we would be unable to turn the last one, which would feel unnatural.</p>
<p>We are now ready for the plugin!</p>
<h3>jQuery</h3>
<p>Using turn.js is really simple. As we already have the markup of the magazine, we just need to call the turn() method. While we are at it, we will also listen for presses on the arrow keys, which will trigger page transitions.</p>
<h4>assets/js/script.js</h4>
<pre class="brush:js">$(function(){

	var mag = $('#magazine');

	// initiazlie turn.js on the #magazine div
	mag.turn();

	// turn.js defines its own events. We are listening
	// for the turned event so we can center the magazine
	mag.bind('turned', function(e, page, pageObj) {

		if(page == 1 &amp;&amp; $(this).data('done')){
			mag.addClass('centerStart').removeClass('centerEnd');
		}
		else if (page == 32 &amp;&amp; $(this).data('done')){
			mag.addClass('centerEnd').removeClass('centerStart');
		}
		else {
			mag.removeClass('centerStart centerEnd');
		}

	});

	setTimeout(function(){
		// Leave some time for the plugin to
		// initialize, then show the magazine
		mag.fadeTo(500,1);
	},1000);

	$(window).bind('keydown', function(e){

		// listen for arrow keys

		if (e.keyCode == 37){
			mag.turn('previous');
		}
		else if (e.keyCode==39){
			mag.turn('next');
		}

	});

});</pre>
<p>You can read more about what events the plugin emits and how to use them, in the <a href="https://github.com/blasten/turn.js/wiki/Reference" target="_blank">turn.js reference</a>.</p>
<p>Now let&#8217;s make it pretty!</p>
<h3>CSS</h3>
<p>We need to set explicit dimensions of the magazine and style the pages and page numbers. turn.js will handle the rest.</p>
<h4>assets/css/styles.css</h4>
<pre class="brush:css">#magazine{
	width:1040px;
	height:520px;
	margin:0 auto;
	position:relative;
	left:0;

	opacity:0;

	-moz-transition:0.3s left;
	-webkit-transition:0.3s left;
	transition:0.3s left;
}

#magazine .page{
	width:520px;
	height:520px;
	background-color:#ccc;
	overflow:hidden;
}

/* Center the magazine when the cover is shown */
#magazine.centerStart{
	left:-260px;
}

/* Center the magazine when the last page is shown */
#magazine.centerEnd{
	left:260px;
}

.page img{
	height:520px;
	width:520px;
	display:block;
}

/* Show a dark shadow when the cover is shown */
.centerStart .turn-page-wrapper:first-child{
	box-shadow:0 0 10px #040404;
}

/* Page Numbers */

span.pageNum{
    background-color: rgba(0, 0, 0, 0.3);
    bottom: 25px;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.25);
    color: #FFFFFF;
    font-size: 11px;
    height: 24px;
    line-height: 22px;
    opacity: 0.9;
    position: absolute;
    text-align: center;
    width: 55px;
}

span.pageNum.left{
	left:0;
	right:auto;
}

span.pageNum.right{
	left:auto;
	right:0;
}

/* Hide the page number on the cover */
#page1 .pageNum{
	display:none;
}</pre>
<p>With this our magazine is complete!</p>
<h3>We&#8217;re done!</h3>
<p>This example works in all recent browsers &#8211; Firefox, Chrome, Safari, Opera and even IE. It is even usable on iOS and Android. You can use this effect as part of photo galleries, templates or even real magazines. However you will have to create a fallback version for older browsers, which don&#8217;t have what it takes to display it properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/03/instagram-magazine-php-jquery/feed/</wfw:commentRss>
		<slash:comments>75</slash:comments>
		</item>
		<item>
		<title>Making an Impressive Product Showcase with CSS3</title>
		<link>http://tutorialzine.com/2012/02/css3-product-showcase/</link>
		<comments>http://tutorialzine.com/2012/02/css3-product-showcase/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 19:00:36 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1865</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/02/css3-product-showcase/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/1865.jpg" class="attachment-tzmedium" alt="Making an Impressive Product Showcase with CSS3" /></a></div> Impress.js is a small, standalone library that makes it easy to design advanced CSS3 presentations with eye-catching effects. But what if we used impress.js for something other than a presentation?]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/02/css3-product-showcase/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/1865.jpg" class="attachment-tzmedium" alt="Making an Impressive Product Showcase with CSS3" /></a></div> <p>A product page is any page on your website that showcases a product. It has to describe its features, give some screenshots, and be descriptive. Naturally, this is the place where you build up the visitor&#8217;s interest towards your product,  but it is getting increasingly difficult to be original in grabbing their attention. Luckily, a new compact JavaScript library can help you make a splash.</p>
<p><a href="https://github.com/bartaz/impress.js/" target="_blank">impress.js</a> is a small, standalone library that makes it easy to design advanced CSS3 presentations with <a href="http://bartaz.github.com/impress.js/" target="_blank">eye-catching effects</a>. But what if we used impress.js for something other than a presentation? This is what we are doing today &#8211; we will be spicing up a plain old product page with some CSS3 magic!</p>
<h3>The HTML</h3>
<p>We start of with a simple HTML5 document that will be the backbone of today&#8217;s example.</p>
<h4>index.html</h4>
<pre class="brush:html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;Impressive CSS3 Product Showcase | Tutorialzine Demo&lt;/title&gt;

        &lt;!-- Google Webfonts and our stylesheet --&gt;
        &lt;link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans+Narrow|Open+Sans:300" /&gt;
        &lt;link rel="stylesheet" href="assets/css/styles.css" /&gt;

        &lt;!--[if lt IE 9]&gt;
          &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
        &lt;![endif]--&gt;
    &lt;/head&gt;

    &lt;body&gt;

		&lt;div id="impress" class="impress-not-supported"&gt;

			&lt;!-- The Slides Will Go Here --&gt;

		&lt;/div&gt;

		&lt;a id="arrowLeft" class="arrow"&gt;&amp;lt;&lt;/a&gt;
		&lt;a id="arrowRight" class="arrow"&gt;&amp;gt;&lt;/a&gt;

        &lt;!-- JavaScript includes --&gt;
		&lt;script src="http://code.jquery.com/jquery-1.7.1.min.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/impress.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/script.js"&gt;&lt;/script&gt;

    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Nothing unusual here. Along with the Google Webfonts include in the head, we also have our main stylesheet (we will go back to it in the next section) and a number of JavaScript source files before the closing body tag.</p>
<p>The <strong>#impress</strong> div will hold the slides. The id is required in order to be recognized by <strong>impress.js</strong> (you can override this by passing a different id to the impress function call in script.js). After this, we have the arrows that initiate the slide transitions.</p>
<p>Last on the page, we have our JavaScript source files. <em>impress.js</em> is standalone and does not need jQuery to work, but we will be including it so we can listen for clicks on the arrows in our <em>script.js</em> file.</p>
<div id="attachment_1866" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/02/css3-product-showcase/"><img class="size-full wp-image-1866" title="CSS3 Product Showcase" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/css3-product-showcase.jpg" alt="CSS3 Product Showcase" width="620" height="460" /></a><p class="wp-caption-text">CSS3 Product Showcase</p></div>
<p>Each of the slides of our showcase contains three elements &#8211; a <strong>title</strong>, a <strong>paragraph</strong> of text, and a smartphone <strong>image</strong>. These are all positioned uniquely for each slide. The promo images and text for this example were taken from <a href="http://www.google.com/nexus/">Google&#8217;s Galaxy Nexus web site</a>.</p>
<p>The elements of the slides are grouped into individual &#8220;<em>step</em>&#8221; divs inside the #impress container. With this we have set the stage for <strong>impress.js</strong>!</p>
<h3>Using impress.js</h3>
<p>With this tiny library, we can create smooth CSS3 transitions between the slides of our showcase. To do this, we have to instruct impress.js on how to orient the slides. This is easy to do &#8211; we will use data attributes on the step divs. These attributes are translated into real CSS3 transformations by the library, depending on the current browser, and affect the slide.</p>
<p>Impress.js supports a number of attributes:</p>
<ul>
<li><strong>data-x</strong>, <strong>data-y</strong>, <strong>data-z</strong> will move the slide on the screen in 3D space;</li>
<li><strong><strong>data-rotate</strong>, data-rotate-x</strong>, <strong>data-rotate-y</strong><strong></strong> rotate the element around the specified axis (in degrees);</li>
<li><strong>data-scale</strong> &#8211; enlarges or shrinks the slide.</li>
</ul>
<p>You can see the markup for the slides below:</p>
<pre class="brush:html">&lt;!-- The first slide retains its default position. We could omit the data attributes --&gt;
&lt;div id="intro" class="step" data-x="0" data-y="0"&gt;
	&lt;h2&gt;Introducing Galaxy Nexus&lt;/h2&gt;
	&lt;p&gt;Android 4.0&lt;br /&gt; Super Amoled 720p Screen&lt;br /&gt;
	&lt;img src="assets/img/nexus_1.jpg" width="232" height="458" alt="Galaxy Nexus" /&gt;
&lt;/div&gt;

&lt;!-- We are offsetting the second slide, rotating it and making it 1.8 times larger --&gt;
&lt;div id="simplicity" class="step" data-x="1100" data-y="1200" data-scale="1.8" data-rotate="190"&gt;
	&lt;h2&gt;Simplicity in Android 4.0&lt;/h2&gt;
	&lt;p&gt;Android 4.0, Ice Cream Sandwich brings an entirely new look and feel..&lt;/p&gt;
	&lt;img src="assets/img/nexus_2.jpg" width="289" height="535" alt="Galaxy Nexus" /&gt;
&lt;/div&gt;

&lt;!-- Same for the rest.. --&gt;
&lt;div id="connect" class="step" data-x="-300" data-y="600" data-scale="0.2" data-rotate="270"&gt;
	&lt;h2&gt;Connect &amp;amp; Share&lt;/h2&gt;
	&lt;p&gt;Real-life sharing is nuanced and rich. Galaxy Nexus makes sharing.. &lt;/p&gt;
	&lt;img src="assets/img/nexus_3.jpg" width="558" height="329" alt="Galaxy Nexus" /&gt;
&lt;/div&gt;

&lt;div id="upload" class="step" data-x="-200" data-y="1500" data-rotate="180"&gt;
	&lt;h2&gt;Instant Upload&lt;/h2&gt;
	&lt;p&gt;Your photos upload themselves with Instant Upload, which makes ..&lt;/p&gt;
	&lt;img src="assets/img/nexus_4.jpg" width="248" height="510" alt="Galaxy Nexus" /&gt;
&lt;/div&gt;

&lt;div id="music" class="step" data-x="-1200" data-y="1000" data-scale="0.8" data-rotate="270"&gt;
	&lt;h2&gt;Jam on with Google Music&lt;/h2&gt;
	&lt;p&gt;Google Music makes discovery, purchase, and listening effortless and..&lt;/p&gt;
	&lt;img src="assets/img/nexus_5.jpg" width="570" height="389" alt="Galaxy Nexus" /&gt;
&lt;/div&gt;</pre>
<p>When the slideshow starts, <em>impress.js</em> will compensate for these transformations, and apply the reverse rules to the #impress div with a smooth CSS transition. The result is the eye-catching presentation you see in the demo. Of course, this comes at the price that you have to manually tweak the data attributes of each slide for the best result.</p>
<h3>The CSS</h3>
<p>To make the presentation work, we will have to apply some CSS rules. The first step is to style the presentation container and declare default styling for the slide elements.</p>
<h4>assets/css/style.css</h4>
<pre class="brush:css">/*----------------------------
	Styling the presentation
-----------------------------*/

#impress:not(.impress-not-supported) .step{
	opacity:0.4;
}

#impress .step{
	width:700px;
	height: 600px;
	position:relative;
	margin:0 auto;

	-moz-transition:1s opacity;
	-webkit-transition:1s opacity;
	transition:1s opacity;
}

#impress .step.active{
	opacity:1;
}

#impress h2{
	font: normal 44px/1.5 'PT Sans Narrow', sans-serif;
	color:#444648;
	position:absolute;
	z-index:10;
}

#impress p{
	font: normal 18px/1.3 'Open Sans', sans-serif;
	color:#27333f;
	position:absolute;
	z-index:10;
}

#impress img{
	position:absolute;
	z-index:1;
}</pre>
<p>As you can see in the rules above, and in the HTML fragment in the beginning of this tutorial, the #impress container is assigned a <strong>.impress-not-supported</strong> class. The class is removed only if the current browser supports the functionality required for the library to run successfully.</p>
<p>Now we need to style the individual slides. I will only include the classes for the first slide here, you can find the rest in <em>assets/css/styles.css</em>.</p>
<pre class="brush:css">/*----------------------------
	Slide 1 - Intro
-----------------------------*/

#impress #intro{
	width: 500px;
}

#intro h2{
	text-align: center;
    width: 100%;
}

#intro p{
	font-size: 22px;
    left: 290px;
    line-height: 1.6;
    top: 220px;
    white-space: nowrap;
}

#intro img{
	top: 120px;
}</pre>
<p>All that is left is for a quick JS snippet to initiate impress.js, and listen for clicks on the arrows.</p>
<h3>jQuery</h3>
<p>To initialize the impress library we need to call the method of the same name. This will also return a new object, with methods for showing the previous / next slides.</p>
<h4>script.js</h4>
<pre class="brush:js">$(function(){

	var imp = impress();

	$('#arrowLeft').click(function(e){
		imp.prev();
		e.preventDefault();
	});

	$('#arrowRight').click(function(e){
		imp.next();
		e.preventDefault();
	});

});</pre>
<p><em>With this our impress-ive product showcase is complete!</em></p>
<h3>Done!</h3>
<p>You can use this example for product and landing pages, feature showcases and with some randomization you could even turn it into an image gallery.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/02/css3-product-showcase/feed/</wfw:commentRss>
		<slash:comments>83</slash:comments>
		</item>
		<item>
		<title>Apple-like Login Form with CSS 3D Transforms</title>
		<link>http://tutorialzine.com/2012/02/apple-like-login-form/</link>
		<comments>http://tutorialzine.com/2012/02/apple-like-login-form/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 16:21:13 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1848</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/02/apple-like-login-form/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/1848.jpg" class="attachment-tzmedium" alt="Apple-like Login Form with CSS 3D Transforms" /></a></div> This time we will use the new CSS3 3D transformations to add interesting effects to an Apple-inspired login form.]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/02/apple-like-login-form/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/1848.jpg" class="attachment-tzmedium" alt="Apple-like Login Form with CSS 3D Transforms" /></a></div> <p>Hey did you know that you can flip elements in 3D space with CSS3? You probably should as this has been possible for nearly two years. First only in Webkit browsers &#8211; Safari and Chrome, but now in Firefox as well. This means that more than half of the world (that use a non IE browser) can see advanced, CSS driven animations and effects.</p>
<p>In this tutorial we will see how we can use these transforms to create an interesting flipping effect on an Apple-inspired form.</p>
<h3>The Idea</h3>
<p>We will have two forms &#8211; login and password recovery, with only one visible at a time. Clicking a link (the ribbons in the example), will trigger a CSS3 rotation on the Y axis, which will reveal the other form with a flipping effect.</p>
<p>We will use jQuery to listen for clicks on the links, and add or remove a class name on the forms&#8217; container element. With CSS we will apply the <strong>rotateY</strong> transformation (a horizontal rotation) to both forms, but with a <em>180deg</em> difference depending on this class. This will make the forms appear on opposite sides of an imaginary platform. To animate the transition, we will use the <a href="https://developer.mozilla.org/en/CSS/CSS_transitions" target="_blank">CSS transition</a> property.</p>
<blockquote class="note"><p>Learn more about <a href="http://www.w3schools.com/css3/css3_3dtransforms.asp" target="_blank">CSS3 3D transforms</a>, read an <a href="http://24ways.org/2010/intro-to-css-3d-transforms" target="_blank">intro</a> or see <a href="http://hacks.mozilla.org/2011/10/css-3d-transformations-in-firefox-nightly/" target="_blank">some demos</a>.</p></blockquote>
<h3>The markup</h3>
<p>We need two forms &#8211; <em>login</em> and <em>recover</em>. Each form will have a submit button, and text/password inputs:</p>
<h4>index.html</h4>
<pre class="brush:html">		&lt;div id="formContainer"&gt;
			&lt;form id="login" method="post" action="./"&gt;
				&lt;a href="#" id="flipToRecover" class="flipLink"&gt;Forgot?&lt;/a&gt;
				&lt;input type="text" name="loginEmail" id="loginEmail" placeholder="Email" /&gt;
				&lt;input type="password" name="loginPass" id="loginPass" placeholder="Password" /&gt;
				&lt;input type="submit" name="submit" value="Login" /&gt;
			&lt;/form&gt;
			&lt;form id="recover" method="post" action="./"&gt;
				&lt;a href="#" id="flipToLogin" class="flipLink"&gt;Forgot?&lt;/a&gt;
				&lt;input type="text" name="recoverEmail" id="recoverEmail" placeholder="Your Email" /&gt;
				&lt;input type="submit" name="submit" value="Recover" /&gt;
			&lt;/form&gt;
		&lt;/div&gt;</pre>
<p>Note the IDs of the elements in the form. We will be using them extensively in the CSS part. Only one of these forms will be visible at a time. The other will be revealed during the flip animation. Each form has a <em>flipLink</em> anchor. Clicking this will toggle (add or remove) the <strong>flipped</strong> class name on the <em>#formContainer</em> div, which will in turn trigger the CSS3 animation.</p>
<div id="attachment_1849" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/02/apple-like-login-form/"><img class="size-full wp-image-1849" title="Apple-like Form with CSS 3D Transforms" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/apple-like-form-css-3d.jpg" alt="Apple-like Form with CSS 3D Transforms" width="620" height="460" /></a><p class="wp-caption-text">Apple-like Form with CSS 3D Transforms</p></div>
<h3>The jQuery Code</h3>
<p>The first important step is to determine whether the current browser supports CSS3 3D transforms at all. If it doesn&#8217;t, we will provide a fallback (the forms will be switched directly). We will also use jQuery to listen for clicks on the <em>flipLink</em> anchors. As we will not be building an actual backend to these forms we will also need to prevent them from being submitted.</p>
<p>Here is the code that does all of the above:</p>
<h4>assets/js/script.js</h4>
<pre class="brush:js">$(function(){

	// Checking for CSS 3D transformation support
	$.support.css3d = supportsCSS3D();

	var formContainer = $('#formContainer');

	// Listening for clicks on the ribbon links
	$('.flipLink').click(function(e){

		// Flipping the forms
		formContainer.toggleClass('flipped');

		// If there is no CSS3 3D support, simply
		// hide the login form (exposing the recover one)
		if(!$.support.css3d){
			$('#login').toggle();
		}
		e.preventDefault();
	});

	formContainer.find('form').submit(function(e){
		// Preventing form submissions. If you implement
		// a backend, you will want to remove this code
		e.preventDefault();
	});

	// A helper function that checks for the
	// support of the 3D CSS3 transformations.
	function supportsCSS3D() {
		var props = [
			'perspectiveProperty', 'WebkitPerspective', 'MozPerspective'
		], testDom = document.createElement('a');

		for(var i=0; i&lt;props.length; i++){
			if(props[i] in testDom.style){
				return true;
			}
		}

		return false;
	}
});</pre>
<p>For convenience, the functionality that checks for 3D CSS3 support is extracted into a separate helper function. It checks for support of the <a href="https://developer.mozilla.org/en/CSS/perspective" target="_blank">perspective</a> property, which is what gives our demo a depth.</p>
<p>We can now move on to the CSS part.</p>
<div id="attachment_1850" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/02/apple-like-login-form/"><img class="size-full wp-image-1850" title="Password Recovery" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/password-recovery.jpg" alt="Password Recovery" width="620" height="400" /></a><p class="wp-caption-text">Password Recovery</p></div>
<h3>The CSS</h3>
<p>CSS will handle everything from the presentation of the forms and form elements, to the animated effects and transitions. We&#8217;ll start with the form container styles.</p>
<h4>assets/css/styles.css</h4>
<pre class="brush:css">#formContainer{
	width:288px;
	height:321px;
	margin:0 auto;
	position:relative;

	-moz-perspective: 800px;
	-webkit-perspective: 800px;
	perspective: 800px;
}</pre>
<p>As well as a <em>width</em>, <em>height</em>, <em>margin</em> and <em>positioning</em>, we also set the <strong>perspective</strong> of the element. This property gives depth to the stage. Without it the animations would appear flat (try disabling it to see what I mean). The greater the value, the farther away the vanishing point.</p>
<p>Next we&#8217;ll style the forms themselves.</p>
<pre class="brush:css">#formContainer form{
	width:100%;
	height:100%;
	position:absolute;
	top:0;
	left:0;

	/* Enabling 3d space for the transforms */
	-moz-transform-style: preserve-3d;
	-webkit-transform-style: preserve-3d;
	transform-style: preserve-3d;

	/* When the forms are flipped, they will be hidden */
	-moz-backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;

	/* Enabling a smooth animated transition */
	-moz-transition:0.8s;
	-webkit-transition:0.8s;
	transition:0.8s;

	/* Configure a keyframe animation for Firefox */
	-moz-animation: pulse 2s infinite;

	/* Configure it for Chrome and Safari */
	-webkit-animation: pulse 2s infinite;
}

#login{
	background:url('../img/login_form_bg.jpg') no-repeat;
	z-index:100;
}

#recover{
	background:url('../img/recover_form_bg.jpg') no-repeat;
	z-index:1;
	opacity:0;

	/* Rotating the recover password form by default */
	-moz-transform:rotateY(180deg);
	-webkit-transform:rotateY(180deg);
	transform:rotateY(180deg);
}</pre>
<p>We first describe the common styles that are shared between both forms. After this we add the unique styles that differentiate them.</p>
<p>The <strong>backface visibility</strong> property is important, as it instructs the browser to hide the backside of the forms. Otherwise we would end up with a mirrored version of the recover form instead of showing the login one. The flip effect is achieved using the <code>rotateY(180deg)</code> transformation. It rotates the element right to left. And as we&#8217;ve declared a <em>transition</em> property, every rotation will be smoothly animated.</p>
<p>Notice the <strong>keyframe</strong> declaration at the bottom of the form section. This defines a repeating (declared by the <em>infinite</em> keyword) <a href="https://developer.mozilla.org/en/CSS/CSS_animations" target="_blank">keyframe animation</a>, which does not depend on user interaction. The CSS description of the animation is given below:</p>
<pre class="brush:css">/* Firefox Keyframe Animation */
@-moz-keyframes pulse{
	0%{		box-shadow:0 0 1px #008aff;}
	50%{	box-shadow:0 0 8px #008aff;}
	100%{	box-shadow:0 0 1px #008aff;}
}

/* Webkit keyframe animation */
@-webkit-keyframes pulse{
	0%{		box-shadow:0 0 1px #008aff;}
	50%{	box-shadow:0 0 10px #008aff;}
	100%{	box-shadow:0 0 1px #008aff;}
}</pre>
<p>Each of the percentage groups corresponds to a time point in the animation. As it is repeating the box shadow will appear as a soft pulsating light.</p>
<p>Now let us see what happens once we&#8217;ve clicked the link, and the <strong>flipped</strong> class is added to <em>#formContainer</em>:</p>
<pre class="brush:css">#formContainer.flipped #login{

	opacity:0;

	/**
	 * Rotating the login form when the
	 * flipped class is added to the container
	 */

	-moz-transform:rotateY(-180deg);
	-webkit-transform:rotateY(-180deg);
	transform:rotateY(-180deg);
}

#formContainer.flipped #recover{

	opacity:1;

	/* Rotating the recover div into view */
	-moz-transform:rotateY(0deg);
	-webkit-transform:rotateY(0deg);
	transform:rotateY(0deg);
}</pre>
<p>The flipped class causes the <em>#login</em> and <em>#recover</em> div to get rotated by 180 degrees. This makes the #login form disappear. But as the #recover one was already facing us with its back side, it gets shown instead of hidden.</p>
<p>The opacity declarations here are only a fix for a bug in the Android browser, which ignores the backface-visibility property and shows a flipped version of the forms instead of hiding them. With this fix, the animation works even on Android and iOS in addition to desktop browsers.</p>
<h3>Done!</h3>
<p>CSS 3D transforms open the doors to all kinds of interesting effects, once reserved only for heavy flash web pages. Now we can have lightweight, crawlable and semantic sites that both look good and provide proper fallbacks for subpar browsers.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/02/apple-like-login-form/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Making a jQuery Countdown Timer</title>
		<link>http://tutorialzine.com/2011/12/countdown-jquery/</link>
		<comments>http://tutorialzine.com/2011/12/countdown-jquery/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 11:02:06 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1781</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/12/countdown-jquery/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/1781.jpg" class="attachment-tzmedium" alt="Making a jQuery Countdown Timer" /></a></div> Today we are going to build a neat jQuery plugin for displaying a countdown timer. It will show the remaining days, hours, minutes and seconds to your event, as well as an animated updates on every second.]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/12/countdown-jquery/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/1781.jpg" class="attachment-tzmedium" alt="Making a jQuery Countdown Timer" /></a></div> <p>When building a <a title="Creating a Stylish Coming Soon Page with jQuery" href="http://tutorialzine.com/2010/10/ajaxed-coming-soon-page/">coming soon</a> or event page, you find yourself in search for a good way to display the remaining time. A countdown gives the feel of urgency, and combined with an email field will yield more signups for your newsletter.</p>
<p>Today we are going to build a neat jQuery plugin for displaying a countdown timer. It will show the remaining days, hours, minutes and seconds to your event, as well as an animated updates on every second. <strong>Note:</strong> the plugin is also available on <a href="https://github.com/martinaglv/jQuery-Countdown" target="_blank">Github</a>.</p>
<p>Let&#8217;s start with the markup!</p>
<h3>The HTML</h3>
<p>We will give the plugin the creative name of &#8220;countdown&#8221;. Called on an empty element, it will fill it with the HTML that is needed for the countdown timer. You don&#8217;t need to do anything but choose the element in which you want to show it.</p>
<h4>Generated markup</h4>
<pre class="brush:html">&lt;div id="countdown" class="countdownHolder"&gt;
	&lt;span class="countDays"&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
	&lt;/span&gt;

	&lt;span class="countDiv countDiv0"&gt;&lt;/span&gt;

	&lt;span class="countHours"&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
	&lt;/span&gt;

	&lt;span class="countDiv countDiv1"&gt;&lt;/span&gt;

	&lt;span class="countMinutes"&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
	&lt;/span&gt;

	&lt;span class="countDiv countDiv2"&gt;&lt;/span&gt;

	&lt;span class="countSeconds"&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
	&lt;/span&gt;

	&lt;span class="countDiv countDiv3"&gt;&lt;/span&gt;
&lt;/div&gt;</pre>
<p>In the above example, the plugin has been originally called on a div with an id of <strong>countdown</strong>. The plugin has then added a <strong>countdownHolder</strong> class to it (so a few styles are applied to the element via CSS).</p>
<p>Inside is the markup for the digits. There are two <strong>digit</strong> spans for every time unit (days, hours, minutes and seconds), which means that you can count down towards a date that is no more than 99 days in the future (for such time frames you should probably not use the timer anyway, it would be discouraging).</p>
<p>The static class of the digits gives them their gradient background and box-shadow. When animated, this class is removed so that these CSS3 touches don&#8217;t slow down the animation. The digits are brought together in groups so you can easily style them. Adding a font-size declaration to .<strong>countDays</strong>, will affect the size of both day digits.</p>
<div id="attachment_1782" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2011/12/countdown-jquery/"><img class="size-full wp-image-1782" title="A jQuery Countdown Timer" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/jquery-countdown-timer.jpg" alt="A jQuery Countdown Timer" width="620" height="260" /></a><p class="wp-caption-text">A jQuery Countdown Timer</p></div>
<p>The <strong>.countDiv</strong> spans are the dividers between the units. The colon is formed with :before/:after elements.</p>
<p>But how is this markup generated exactly?</p>
<h3>The jQuery</h3>
<p>First let&#8217;s write two helper functions used by the plugin:</p>
<ul>
<li><strong>init</strong> generates the markup you saw above;</li>
<li><strong>switchDigit</strong> takes a .position span and animates the digits inside it;</li>
</ul>
<p>Extracting this functionality as separate functions allows us to keep the plugin code clean.</p>
<h4>assets/countdown/jquery.countdown.js</h4>
<pre class="brush:js">	function init(elem, options){
		elem.addClass('countdownHolder');

		// Creating the markup inside the container
		$.each(['Days','Hours','Minutes','Seconds'],function(i){
			$('&lt;span class="count'+this+'"&gt;').html(
				'&lt;span class="position"&gt;\
					&lt;span class="digit static"&gt;0&lt;/span&gt;\
				&lt;/span&gt;\
				&lt;span class="position"&gt;\
					&lt;span class="digit static"&gt;0&lt;/span&gt;\
				&lt;/span&gt;'
			).appendTo(elem);

			if(this!="Seconds"){
				elem.append('&lt;span class="countDiv countDiv'+i+'"&gt;&lt;/span&gt;');
			}
		});

	}

	// Creates an animated transition between the two numbers
	function switchDigit(position,number){

		var digit = position.find('.digit')

		if(digit.is(':animated')){
			return false;
		}

		if(position.data('digit') == number){
			// We are already showing this number
			return false;
		}

		position.data('digit', number);

		var replacement = $('&lt;div&gt;',{
			'class':'digit',
			css:{
				top:'-2.1em',
				opacity:0
			},
			html:number
		});

		// The .static class is added when the animation
		// completes. This makes it run smoother.

		digit
			.before(replacement)
			.removeClass('static')
			.animate({top:'2.5em',opacity:0},'fast',function(){
				digit.remove();
			})

		replacement
			.delay(100)
			.animate({top:0,opacity:1},'fast',function(){
				replacement.addClass('static');
			});
	}</pre>
<p>Great! Now let&#8217;s move on with the plugin body. Our plugin must take an object with parameters for better configurability &#8211; a timestamp of the period we are counting towards, and a callback function, executed on every tick and passed the remaining time. For brevity, I&#8217;ve omitted the functions above from the code.</p>
<h4>assets/countdown/jquery.countdown.js</h4>
<pre class="brush:js">(function($){

	// Number of seconds in every time division
	var days	= 24*60*60,
		hours	= 60*60,
		minutes	= 60;

	// Creating the plugin
	$.fn.countdown = function(prop){

		var options = $.extend({
			callback	: function(){},
			timestamp	: 0
		},prop);

		var left, d, h, m, s, positions;

		// Initialize the plugin
		init(this, options);

		positions = this.find('.position');

		(function tick(){

			// Time left
			left = Math.floor((options.timestamp - (new Date())) / 1000);

			if(left &lt; 0){
				left = 0;
			}

			// Number of days left
			d = Math.floor(left / days);
			updateDuo(0, 1, d);
			left -= d*days;

			// Number of hours left
			h = Math.floor(left / hours);
			updateDuo(2, 3, h);
			left -= h*hours;

			// Number of minutes left
			m = Math.floor(left / minutes);
			updateDuo(4, 5, m);
			left -= m*minutes;

			// Number of seconds left
			s = left;
			updateDuo(6, 7, s);

			// Calling an optional user supplied callback
			options.callback(d, h, m, s);

			// Scheduling another call of this function in 1s
			setTimeout(tick, 1000);
		})();

		// This function updates two digit positions at once
		function updateDuo(minor,major,value){
			switchDigit(positions.eq(minor),Math.floor(value/10)%10);
			switchDigit(positions.eq(major),value%10);
		}

		return this;
	};

	/* The two helper functions go here */</pre>
<pre class="brush:js">})(jQuery);</pre>
<p>The tick function calls itself every second. Inside it, we calculate the time difference between the given timestamp and the current date. The <strong>updateDuo</strong> function then updates the digits comprising the time unit.</p>
<p><strong>The plugin is ready!</strong> Here is how to use it (as seen in the demo):</p>
<h4>assets/js/script.js</h4>
<pre class="&quot;brush:js">$(function(){

	var note = $('#note'),
		ts = new Date(2012, 0, 1),
		newYear = true;

	if((new Date()) &gt; ts){
		// The new year is here! Count towards something else.
		// Notice the *1000 at the end - time must be in milliseconds
		ts = (new Date()).getTime() + 10*24*60*60*1000;
		newYear = false;
	}

	$('#countdown').countdown({
		timestamp	: ts,
		callback	: function(days, hours, minutes, seconds){

			var message = "";

			message += days + " day" + ( days==1 ? '':'s' ) + ", ";
			message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
			message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
			message += seconds + " second" + ( seconds==1 ? '':'s' ) + " &lt;br /&gt;";

			if(newYear){
				message += "left until the new year!";
			}
			else {
				message += "left to 10 days from now!";
			}

			note.html(message);
		}
	});

});</pre>
<p>Of course, for this to work, you will have to include the css and js file from the countdown folder in your page.</p>
<h3>Done!</h3>
<p>You can use this script as the perfect addition to every launch page. The best thing about it is that it doesn&#8217;t use a single image, everything is done with CSS alone. Increasing or decreasing the font size will result in everything scaling nicely, and you only need a <strong>display:none</strong> declaration to hide the units you don&#8217;t need.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/12/countdown-jquery/feed/</wfw:commentRss>
		<slash:comments>128</slash:comments>
		</item>
		<item>
		<title>Shiny Knob Control with jQuery and CSS3</title>
		<link>http://tutorialzine.com/2011/11/pretty-switches-css3-jquery/</link>
		<comments>http://tutorialzine.com/2011/11/pretty-switches-css3-jquery/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 15:00:50 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1689</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/11/pretty-switches-css3-jquery/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/11/1689.jpg" class="attachment-tzmedium" alt="Shiny Knob Control with jQuery and CSS3" /></a></div> In this tutorial we will be writing a jQuery plugin for creating a shiny knob control, suitable for use in control panels and other administrative pages.]]></description>
				<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/11/pretty-switches-css3-jquery/"><img width="620" height="340" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/11/1689.jpg" class="attachment-tzmedium" alt="Shiny Knob Control with jQuery and CSS3" /></a></div> <p>In this tutorial we will be writing a jQuery plugin for creating a shiny knob control. Aptly named knobKnob, this plugin will use CSS3 transformations and jQuery&#8217;s new event handling methods to give visitors of your website a new way of interactively choosing a value from a range.</p>
<p><a href="https://github.com/martinaglv/KnobKnob" target="_blank">KnobKnob is also on Github.</a></p>
<p><strong>Update:</strong> Thanks to <a href="https://github.com/ranyefet" target="_blank">ranyefet</a> the plugin now works on mobile devices [<a href="https://github.com/martinaglv/KnobKnob/commit/76fb3845e4f70dd8509c4a7d5f45dfe3d4e10b28" target="_blank">changes</a>].</p>
<h3>The HTML</h3>
<p>The HTML markup for the page is rather straightforward. We are only going to need a placeholder element for the control &#8211; the rest is going to be dynamically generated by the plugin. Just in case, here is the complete markup of the page:</p>
<h4>index.html</h4>
<pre class="brush:html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;Shiny Switches with CSS3 &amp;amp; jQuery | Tutorialzine Demo&lt;/title&gt;

        &lt;!-- CSS stylesheets --&gt;
        &lt;link rel="stylesheet" href="assets/css/styles.css" /&gt;
        &lt;link rel="stylesheet" href="assets/knobKnob/knobKnob.css" /&gt;

        &lt;!--[if lt IE 9]&gt;
          &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
        &lt;![endif]--&gt;
    &lt;/head&gt;

    &lt;body&gt;

		&lt;section id="main"&gt;

			&lt;div id="bars"&gt;
				&lt;div id="control"&gt;
					&lt;!-- The knob markup will go here --&gt;
				&lt;/div&gt;
                                &lt;!-- The colorful dividers will go here --&gt;
			&lt;/div&gt;

		&lt;/section&gt;

        &lt;!-- JavaScript includes --&gt;
		&lt;script src="http://code.jquery.com/jquery-1.7.1.min.js"&gt;&lt;/script&gt;
		&lt;script src="assets/knobKnob/transform.js"&gt;&lt;/script&gt;
		&lt;script src="assets/knobKnob/knobKnob.jquery.js"&gt;&lt;/script&gt;
		&lt;script src="assets/js/script.js"&gt;&lt;/script&gt;

    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>First we include the latest version of jQuery, <a href="https://github.com/louisremi/jquery.transform.js" target="_blank">transform.js</a> which levels cross-browser support of the CSS3 transform properties we will be using, the knobKnob plugin file and script.js, which pulls everything together.</p>
<p>The #control div is where the plugin markup will be generated. Below we will insert divs that will become the colorful bars around it. They are not part of the KnobKnob plugin, we will be showing them depending on the chosen value in the control. KnobKnob also comes with a stylesheet that determines the looks of the knob. You can see it included in the head section.</p>
<p>Now lets write this plugin!</p>
<div id="attachment_1697" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2011/11/pretty-switches-css3-jquery/"><img class="size-full wp-image-1697" title="Shiny Knob Control" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/11/shiny-switch-rotation.jpg" alt="Shiny Knob Control" width="620" height="354" /></a><p class="wp-caption-text">Shiny Knob Control</p></div>
<h3>The jQuery Code</h3>
<p>You can find the plugin source files in the knobKnob folder. To use it in your project simply unzip it in your website&#8217;s assets folder and include the files you find inside. Here is the actual plugin file:</p>
<h4>assets/knobKnob/knobKnob.jquery.js</h4>
<pre class="brush:js">/**
 * @name		jQuery KnobKnob plugin
 * @author		Martin Angelov
 * @version 	1.0
 * @url			http://tutorialzine.com/2011/11/pretty-switches-css3-jquery/
 * @license		MIT License
 */

(function($){

	$.fn.knobKnob = function(props){

		var options = $.extend({
			snap: 0,
			value: 0,
			turn: function(){}
		}, props || {});

		var tpl = '&lt;div class="knob"&gt;\
				&lt;div class="top"&gt;&lt;/div&gt;\
				&lt;div class="base"&gt;&lt;/div&gt;\
			&lt;/div&gt;';

		return this.each(function(){

			var el = $(this);
			el.append(tpl);

			var knob = $('.knob',el)
				knobTop = knob.find('.top'),
				startDeg = -1,
				currentDeg = 0,
				rotation = 0,
				lastDeg = 0,
				doc = $(document);

			if(options.value &gt; 0 &amp;&amp; options.value &lt;= 359){
				rotation = currentDeg = options.value;
				knobTop.css('transform','rotate('+(currentDeg)+'deg)');
				options.turn(currentDeg/359);
			}

			knob.on('mousedown', function(e){

				e.preventDefault();

				var offset = knob.offset();
				var center = {
					y : offset.top + knob.height()/2,
					x: offset.left + knob.width()/2
				};

				var a, b, deg, tmp,
					rad2deg = 180/Math.PI;

				knob.on('mousemove.rem',function(e){

					a = center.y - e.pageY;
					b = center.x - e.pageX;
					deg = Math.atan2(a,b)*rad2deg;

					// we have to make sure that negative
					// angles are turned into positive:
					if(deg&lt;0){
						deg = 360 + deg;
					}

					// Save the starting position of the drag
					if(startDeg == -1){
						startDeg = deg;
					}

					// Calculating the current rotation
					tmp = Math.floor((deg-startDeg) + rotation);

					// Making sure the current rotation
					// stays between 0 and 359
					if(tmp &lt; 0){
						tmp = 360 + tmp;
					}
					else if(tmp &gt; 359){
						tmp = tmp % 360;
					}

					// Snapping in the off position:
					if(options.snap &amp;&amp; tmp &lt; options.snap){
						tmp = 0;
					}

					// This would suggest we are at an end position;
					// we need to block further rotation.
					if(Math.abs(tmp - lastDeg) &gt; 180){
						return false;
					}

					currentDeg = tmp;
					lastDeg = tmp;

					knobTop.css('transform','rotate('+(currentDeg)+'deg)');
					options.turn(currentDeg/359);
				});

				doc.on('mouseup.rem',function(){
					knob.off('.rem');
					doc.off('.rem');

					// Saving the current rotation
					rotation = currentDeg;

					// Marking the starting degree as invalid
					startDeg = -1;
				});

			});
		});
	};

})(jQuery);</pre>
<p>The plugin takes a number of options as a parameter object &#8211; snap, value and turn:</p>
<ul>
<li><strong>snap</strong> is a number of degrees that are snapped to zero. You can test this by slowly turning the knob down;</li>
<li><strong>value</strong> is the initial rotation of the knob (also in degrees);</li>
<li><strong>turn</strong> is a callback function that is called every time the knob is turned. Its only argument is a ratio (from 0 to 1) of the rotation. We will use this function in a moment to determine how many of the colorful dividers to show.</li>
</ul>
<p>In the code above you can see that we are using the Math.atan2 function (as we did in the <a title="jQuery PointPoint – A Plugin For Pointing To Things" href="http://tutorialzine.com/2011/09/jquery-pointpoint-plugin/">PointPoint plugin</a>) to calculate the angle (in radians) between the mouse pointer and the center of the knob. By keeping track of the angle in the start and end position of the drag, we can determine how much to rotate the knob.</p>
<p>Later we are also using jQuery 1.7&#8242;s new methods for manipulating event listeners &#8211; <a href="http://api.jquery.com/on/" target="_blank">on</a> and <a href="http://api.jquery.com/off/" target="_blank">off</a>.</p>
<p>Now lets see how we can use this plugin.</p>
<h4>assets/js/script.js</h4>
<pre class="brush:js">$(function(){

	var colors = [
		'26e000','2fe300','37e700','45ea00','51ef00',
		'61f800','6bfb00','77ff02','80ff05','8cff09',
		'93ff0b','9eff09','a9ff07','c2ff03','d7ff07',
		'f2ff0a','fff30a','ffdc09','ffce0a','ffc30a',
		'ffb509','ffa808','ff9908','ff8607','ff7005',
		'ff5f04','ff4f03','f83a00','ee2b00','e52000'
	];

	var rad2deg = 180/Math.PI;
	var deg = 0;
	var bars = $('#bars');

	for(var i=0;i&lt;colors.length;i++){

		deg = i*12;

		// Create the colorbars

		$('&lt;div class="colorBar"&gt;').css({
			backgroundColor: '#'+colors[i],
			transform:'rotate('+deg+'deg)',
			top: -Math.sin(deg/rad2deg)*80+100,
			left: Math.cos((180 - deg)/rad2deg)*80+100,
		}).appendTo(bars);
	}

	var colorBars = bars.find('.colorBar');
	var numBars = 0, lastNum = -1;

	$('#control').knobKnob({
		snap : 10,
		value: 154,
		turn : function(ratio){
			numBars = Math.round(colorBars.length*ratio);

			// Update the dom only when the number of active bars
			// changes, instead of on every move

			if(numBars == lastNum){
				return false;
			}
			lastNum = numBars;

			colorBars.removeClass('active').slice(0, numBars).addClass('active');
		}
	});

});</pre>
<p>The colorful bars that are displayed around the knob are not part of the plugin. And they shouldn&#8217;t be &#8211; the plugin only handles the control itself which makes it easier to reuse it.</p>
<p>The code above creates a set of 30 divs with colors gradually going from green to red. These are then rotated by 12 degree increments. Thanks to the <strong>turn</strong> callback function passed to the plugin, this code can determine how many of the colorful bars to show. You can see the rest of the bar styling in <em>assets/css/styles.css</em>.</p>
<h3>We are done!</h3>
<p>With this our plugin is complete! You can use it as part of control panels and other administrative pages, everywhere you want to give users the ability to choose from a pool of values. Next time <a title="What You Need To Know About The HTML5 Slider Element" href="http://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/">we will use this plugin to enhance the new range form element</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/11/pretty-switches-css3-jquery/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc
Object Caching 1368/1505 objects using apc
Content Delivery Network via cdn.tutorialzine.com

 Served from: tutorialzine.com @ 2013-05-24 00:34:05 by W3 Total Cache -->