<?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>onlyWebPro &#187; JavaScript</title>
	<atom:link href="http://www.onlywebpro.com/category/tutorials/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.onlywebpro.com</link>
	<description>For Designers &#38; Developers</description>
	<lastBuildDate>Sat, 18 May 2013 08:05:47 +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>Make A jQuery Sticky Header In 5 Minutes</title>
		<link>http://www.onlywebpro.com/2013/04/03/make-a-jquery-sticky-header-in-5-minutes/</link>
		<comments>http://www.onlywebpro.com/2013/04/03/make-a-jquery-sticky-header-in-5-minutes/#comments</comments>
		<pubDate>Wed, 03 Apr 2013 03:09:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2978</guid>
		<description><![CDATA[In this tutorial, we will create a sticky ribbon, where a normal looking ribbon suddenly sticks to the page when the page is scrolled.]]></description>
				<content:encoded><![CDATA[<p>Many of us have seen this sticky page header effects &ndash; The page header is initially on its original place above the content, but as soon we start scrolling down the page, it sticks at the top of the page. When we scrolling up the page, the sticky header stops sticking and returns to its original position.</p>
<p>Still not understand what I&#8217;m talking about? No worry, I thought I should give you a simple example. Let&#8217;s take a look on the demo before we proceed to tutorial section.</p>
<p><a href="http://www.onlywebpro.com/demo/jquery/index.html" class="demo_btn" target="_blank">View Demo</a></p>
<h3>The HTML Structure</h3>
<p>In this tutorial, we will create a sticky ribbon, where a normal looking ribbon suddenly sticks to the page when the page is scrolled. I&#8217;m sure you are already familiar with HTML elements. In this example, we are going to start out with the following:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Demo: jQuery Sticky Header On Scroll | onlyWebPro.com&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;demo_wrapper&quot;&gt;
  &lt;div id=&quot;logo&quot;&gt;
    &lt;h1&gt;Make Money&lt;/h1&gt;
  &lt;/div&gt;
  &lt;!-- END logo --&gt;
  &lt;div id=&quot;stickyribbon&quot;&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.investopedia.com/investing/investing-basics/&quot; target=&quot;_blank&quot;&gt;Investing-Basics&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.investopedia.com/investing/bonds-and-fixed-income/&quot; target=&quot;_blank&quot;&gt;Bonds &amp;amp; Fixed Income&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.investopedia.com/forex/&quot; target=&quot;_blank&quot;&gt;Forex&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.investopedia.com/investing/fundamental-analysis/&quot; target=&quot;_blank&quot;&gt;Fundamental Analysis&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div id=&quot;page_content&quot;&gt;
    &lt;p&gt;This is a demo page of &quot;&lt;a href=&quot;http://www.onlywebpro.com/2013/03/04/make-a-jquery-sticky-header-in-5-minutes/&quot; title=&quot;Learn to develop jQuery Sticky Header&quot;&gt;Make A jQuery Sticky Header In 5 Minutes&lt;/a&gt;&quot; post. If you want to find out more about making jQuery Sticky Header, pleae log on to &lt;a href=&quot;http://www.onlywebpro.com&quot; title=&quot;Web Development Tutorial Website&quot;&gt;onlyWebPro.com&lt;/a&gt;.&lt;/p&gt;
    &lt;h2&gt;Introduction To Growth Investing&lt;/h2&gt;
    &lt;p&gt;People have many different styles and tastes when it comes to money, but making your money grow is typically considered the most fundamental investment objective. The best way to accomplish this goal will vary according to factors such as the investor's risk tolerance and time horizon. But there are some principles and techniques that are applicable for many different types of investors and growth strategies. &lt;/p&gt;
    &lt;p&gt;&lt;img src=&quot;money.jpg&quot;  width=&quot;860&quot; height=&quot;600&quot; alt=&quot;wall street - New York Stock Exchange&quot; /&gt;&lt;br /&gt;
      &lt;em&gt;Image courtesy of Kadellar (Wikipedia.com)&lt;/em&gt;&lt;/p&gt;
    &lt;h3&gt;Types of Growth Investments&lt;/h3&gt;
    &lt;p&gt;&lt;em&gt;&lt;strong&gt;Small-Cap Stocks&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;
      The size of a company is based on its market capitalization, or net worth. There is no exact, universal definition of what is considered to be &quot;small cap&quot; compared to micro, mid or large cap, but most analysts classify any company with a capitalization of between $300 million and $2 billion as a small-cap firm. Companies in this category are often still in their initial phase of growth and their stocks have the potential for substantial appreciation in price. Small-cap stocks have historically posted higher returns than their blue-chip cousins, but they are also considerably more volatile and carry a higher degree of risk. Small-cap stocks have also often outperformed large-cap stocks during periods of recovery from recessions.&lt;/p&gt;
    &lt;p&gt;&lt;em&gt;&lt;strong&gt;Technology and Healthcare Stocks&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;
      Companies that develop new technologies or offer innovations in healthcare can be excellent choices for investors who are looking for a home-run play in their portfolios. The stocks of companies that develop popular or revolutionary products can rise exponentially in price in a relatively short period of time. For example, the price of Pfizer was just under $5 a share in 1994 before Viagra was released. This blockbuster drug took the company's stock price to above $30 a share over the next five years, thanks to FDA approval of the drug in 1998.&lt;/p&gt;
    &lt;p&gt;&lt;em&gt;&lt;strong&gt;Speculative Investments&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;
      Thrill seekers and speculators look to high-risk growth instruments such as penny stocks, futures and options contracts, foreign currency and speculative real estate such as undeveloped land. There are also oil and gas drilling partnerships and private equity for aggressive investors in high income brackets. Those who pick the right choices in this arena can see a return on capital of many times their initial investment, but they can also often lose every cent of their principal.&lt;/p&gt;
    &lt;h3&gt;The Bottom Line&lt;/h3&gt;
    &lt;p&gt;Growth investing is a complex subject that is often closely coupled with other subjects such as fundamental analysis, technical analysis and market research. There are many more growth strategies used by individual and institutional investors, and a complete listing of them is far beyond the scope of this article. For more information on growth strategies for your investments, consult your broker or financial advisor. &lt;/p&gt;
    &lt;hr /&gt;
    &lt;p&gt;Notes: Contents are retreives from &lt;a href=&quot;http://www.investopedia.com&quot; target=&quot;_blank&quot;&gt;Investopedia.com&lt;/a&gt; for demostration purpose only.&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;!-- END demo_wrapper --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>As you can observed from the above HTML structure, we have a main container with named &#8220;<strong>demo_wrapper</strong>&#8220;. Inside, we have &#8220;<strong>logo</strong>&#8220;, &#8220;<strong>stickyribbon</strong>&#8221; and &#8220;<strong>page_content</strong>&#8221; divisions. The &#8220;stickyribbon&#8221; is the main focus element in this tutorial. We are going to add some JavaScript later, to make it become &#8220;sticky&#8221; when users scrolling down the page.</p>
<h3>The CSS</h3>
<pre class="brush: css; title: ; notranslate">
&lt;style type=&quot;text/css&quot;&gt;
body {
	background: #E8E9E4;
	font-family: Arial,sans-serif;
	padding: 20px 0;
}

h1 {
	color: #28639c;
    font-size: 60px;
    font-weight: bold;
    letter-spacing: -6px;
    margin: 0;	
}

h2 {
	border-bottom: 1px solid #ddd;
	color: #28639C;
	font-size: 24px;
	font-weight: bold;
}

p {
	margin: 0 0 25px;	
}

a {
	color: #28639C;
}

#demo_wrapper {
	background: #fff;
	-moz-box-shadow:    0 0 8px 0 rgba(0, 0, 0, 0.1);
  	-webkit-box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.1);
  	box-shadow:         0 0 8px 0 rgba(0, 0, 0, 0.1);
	margin: 0 auto;
	width: 960px;	
}

#logo {
	padding: 40px 50px 30px;	
}

#stickyribbon {
	background: url(ribbon_corner.png) no-repeat center bottom;
	color: #fff;
	height: 60px;
	margin-left: -20px;
	width: 1000px;
}

#stickyribbon ul {
	list-style-type: none;
	margin: 0 10px;
	padding: 10px 40px 15px;
	-moz-box-shadow:    0 12px 5px -6px rgba(0, 0, 0, 0.5);
  	-webkit-box-shadow: 0 12px 5px -6px rgba(0, 0, 0, 0.5);
  	box-shadow:         0 12px 5px -6px rgba(0, 0, 0, 0.5);
}

#stickyribbon ul li {
	display: inline;
	font-size: 16px;
	font-weight: bold;
	margin: 0 20px;
}

#stickyribbon ul li a {
	color: #fff;
	text-decoration: none;
}

#stickyribbon ul li a:hover {
	color: #c9e0f7;	
}

#page_content {
	padding: 30px 50px;	
}
&lt;/style&gt;
</pre>
<p>The CSS styling for this tutorial is pretty simple, I&#8217;m not going to go into details on every single style, let&#8217;s just concentrate on these two &ndash; &#8220;<strong>#demo_wrapper</strong>&#8221; &amp; &#8220;<strong>#stickyribbon</strong>&#8220;. As you observed, the width of the #demo_wrapper &amp; #stickyribbon is slightly different, we make the #stickyribbon wider than the #demo_wrapper to create the illusion of wrapping the #demo_wrapper.</p>
<p>Here is the ribbon that we are using. You can wither create your own or use the following image.<br />
<img src="http://www.onlywebpro.com/wp-content/uploads/2013/12/ribbon_corner.png" alt="Sticky Ribbon" width="570" height="34" class="aligncenter size-full wp-image-2995" /></p>
<h3>The JavaScript</h3>
<pre class="brush: jscript; title: ; notranslate">
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){
	var stickyRibbonTop = $('#stickyribbon').offset().top;
	 
	$(window).scroll(function(){
		if( $(window).scrollTop() &gt; stickyRibbonTop ) {
			$('#stickyribbon').css({position: 'fixed', top: '0px'});
		} else {
			$('#stickyribbon').css({position: 'static', top: '0px'});
		}
	});
});
&lt;/script&gt;
</pre>
<p>Now is the time to apply some magic to our ribbon. At first, we include the latest jQuery library from Google directory. Next, we determine the offset of the &#8220;<strong>stickyribbon</strong>&#8220;. Once done that, we bind the scroll event to window object, then we start checking <strong>IF window.scrollTop exceeds the #stickyheader’s offsetTop</strong>, we simply set #stickyheader’s css as position: fixed; top: 0px. As soon as window.scrollTop drops below the offset, we make it stick back to its original position using position: static, the default positioning of the element.</p>
<p>We&#8217;ve done!</p>
<p><a href="http://www.onlywebpro.com/demo/jquery/index.html" class="demo_btn" target="_blank">View Demo</a></p>
<h3>Conclusion</h3>
<p>You&#8217;ve just learned to make a jQuery ribbon, sticks at the top of the page when scrolling down and return to its original position when scrolling up the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2013/04/03/make-a-jquery-sticky-header-in-5-minutes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Sequential Animations in jQuery</title>
		<link>http://www.onlywebpro.com/2013/02/18/create-sequential-animations-in-jquery/</link>
		<comments>http://www.onlywebpro.com/2013/02/18/create-sequential-animations-in-jquery/#comments</comments>
		<pubDate>Mon, 18 Feb 2013 03:24:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2832</guid>
		<description><![CDATA[In this tutorial, I will demostrate 3 easy ways to create sequential animations in jQuery.]]></description>
				<content:encoded><![CDATA[<p>In this tutorial, I will demostrate 3 easy ways to create sequential animations in jQuery. if you would like to display a set of elements sequentially using CSS3, please read our past tutorial &ndash; <a href="http://www.onlywebpro.com/2012/05/27/create-banner-using-css-animation-and-keyframe/" title="Create Banner Using CSS Animation &#038; Keyframe " target="_blank">&#8220;Create Banner Using CSS Animation &amp; Keyframe&#8221;</a>.</p>
<h3>Setup HTML Structure</h3>
<p>First of all, we need to create a basic HTML structure for applying sequential animation later. Here is how our HTML looks like:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Demo: Display Elements Sequentially with jQuery | onlyWebPro.com&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;a href=&quot;#&quot; class=&quot;abc&quot;&gt;ABC&lt;/a&gt;
    &lt;a href=&quot;#&quot; class=&quot;def&quot;&gt;DEF&lt;/a&gt;
    &lt;a href=&quot;#&quot; class=&quot;ghi&quot;&gt;GHI&lt;/a&gt;
    &lt;a href=&quot;#&quot; class=&quot;jkl&quot;&gt;JKL&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>Method 1: Using jQuery .ep() Method</h3>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
	(function() {  
	   var elem = $('a').hide();  
		  var i = 0;  
		  (function displayImages() {  
			 elem.eq(i++).fadeIn(200, displayImages);  
		  })();    
	})();  
});
&lt;/script&gt;
</pre>
<p>Here is how we create sequential animations in jQuery. Let&#8217;s say we want all the &lt;a&gt; elements fade in sequentially. So, the first thing is to hide all elements when the DOM is ready. then we instruct the browser to self-executing a function named &#8220;<strong>displayImages</strong>&#8221; which contains the fade in method.</p>
<p>The <strong>elem.eq(i++)</strong> refers to the &lt;a&gt; elements. The .eq() method constructs a new jQuery object from one element within the set. The supplied index identifies the position of the &lt;a&gt; element in the set.</p>
<p>When the <strong>elem.eq(i++)</strong> refers to an element that <strong>DOESN&#8221;T EXIST</strong> in the wrapped set, then the subsequent methods in the chain (example: fadeIn method) will never be called.</p>
<p><a href="http://www.onlywebpro.com/demo/jquery/sequential-animations1.html" target="_blank" class="demo_btn">View Demo Method 1</a></p>
<h3>Method 2: Using jQuery .ep() &amp; .slice() Method</h3>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
	$('a').hide();                    
	(function animatenext(elem){
		elem.eq(0).fadeIn(&quot;slow&quot;, function(){
			(elem=elem.slice(1)).length &amp;&amp; animatenext(elem);
		});
	})($('a'))
});
&lt;/script&gt;
</pre>
<p>This method is slightly different than method 1. This method contains .slice() method, which used to reduce the set of matched elements to a subset specified by a range of indices.</p>
<p><a href="http://www.onlywebpro.com/demo/jquery/sequential-animations2.html" target="_blank" class="demo_btn">View Demo Method 2</a></p>
<h3>Method 3: Silly But Not Stupid (Manually Creating Effects)</h3>
<p>Let&#8217;s say we only want the first &lt;a&gt; element to <strong>SLIDE IN</strong> from top, then the rest of the &lt;a&gt; fade in right after the first &lt;a&gt; element appeared on screen, so how can we achieve that? Here is the most simple method to do that:</p>
<p>We need to apply some CSS styles to our first &lt;a&gt; element before applying any jQuery function. Following tells the browser to positioned the first &lt;a&gt; element out of the viewport when the page is loading.</p>
<pre class="brush: css; title: ; notranslate">
&lt;style type=&quot;text/css&quot;&gt;
	.abc {
		position: relative;
		top: -100px;
	}
&lt;/style&gt;
</pre>
<p>Next, we apply the following jQuery code to achieve the effects that we just mentioned above:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
	$(&quot;a&quot;).hide();
	(function() {
		$(&quot;.abc&quot;).show().animate({top: &quot;0&quot;}, &quot;slow&quot;, function() {
		  $(&quot;.def&quot;).fadeIn(&quot;slow&quot;, function(){
			$(&quot;.ghi&quot;).fadeIn(&quot;slow&quot;, function(){
			  $(&quot;.jkl&quot;).fadeIn(&quot;slow&quot;);
			});
		  });
		});
	 })();
});
&lt;/script&gt;
</pre>
<p>That&#8217;s it! Save your document and preview it on browser! You will see the first &lt;a&gt; element <strong>SLIDE IN</strong> from top, then the rest of the &lt;a&gt; fade in right after the first &lt;a&gt; element appeared on screen!</p>
<p><a href="http://www.onlywebpro.com/demo/jquery/sequential-animations3.html" target="_blank" class="demo_btn">View Demo Method 3</a></p>
<p>Follow us on either <a href="http://www.facebook.com/pages/Connect-with-onlyWebPro/149917668368025" title="onlyWebPro on Facebook" target="_blank">Facebook</a>, <a href="http://www.twitter.com/onlyWebPro" title="onlyWebPro on Twitter" target="_blank">Twitter</a>,<a href="https://plus.google.com/100910543735224109915" title="onlyWebPro on Google Plus" target="_blank"> Google+</a> or <a href="http://www.onlywebpro.com/feed/" title="onlyWebPro RSS Feed">subscribe to the onlyWebpro RSS Feed</a> for the best web development tutorials on the web.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2013/02/18/create-sequential-animations-in-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Develop A jQuery Parallax Scrolling Framework</title>
		<link>http://www.onlywebpro.com/2013/01/28/develop-a-jquery-parallax-scrolling-framework/</link>
		<comments>http://www.onlywebpro.com/2013/01/28/develop-a-jquery-parallax-scrolling-framework/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 02:15:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2799</guid>
		<description><![CDATA[In this tutorial, we are going to shows you how to build your own Parallax Scrolling effect powered by jQuery.]]></description>
				<content:encoded><![CDATA[<h3>Introduction to Parallax Scrolling</h3>
<p>The Parallax Scrolling effect is one of the popular design trend in web industry. It is a technique to create an illusion of depth by using multiple background images that move at different speeds as the user scrolls down or up a website.</p>
<p>Still not understand how it works? Let&#8217;s check out the demo!</p>
<p><a href="http://www.onlywebpro.com/demo/jquery/parallax/parallax.html" target="_blank" class="demo_btn">View Demo</a></p>
<h3>The Concept</h3>
<p>As you viewed the demo above, the page contains 4 main content layers, which is text, bg1, bg2 and bg3. Each of these layers are given an z-index, so that the foreground layers appear above the background layers. Let&#8217;s sorting all layers in this way:</p>
<ul>
<li>bg1: The <strong>background layer</strong>.</li>
<li>bg2: The secondary background layer<strong> appears above bg1.</strong></li>
<li>bg3: This layer <strong>appear above bg2</strong>. We use it to store the main object / image.</li>
<li>text: This is the <strong>foreground layer</strong> that contains the text.</li>
</ul>
<p>As user scrolls down the page, the 4 main layers are animated independently of one another to create an illusion of depth.</p>
<h3>The HTML Markup</h3>
<p>Following is the HTML structure of our page:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;meta name=&quot;description&quot; content=&quot;Demo of building jQuery parallax scrolling framework&quot; /&gt;
&lt;title&gt;jQuery Parallax Scrolling Effects | onlyWebPro.com&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div class=&quot;parallax_wrapper&quot;&gt;
	&lt;div class=&quot;text&quot;&gt;
    	&lt;div id=&quot;text-1&quot;&gt;
            &lt;h1&gt;The Demo of jQuery Parallax Scrolling&lt;/h1&gt;
            &lt;p&gt;This is a demo page that shows you the simplest parallax scrolling technique you've ever came across!&lt;/p&gt;
        &lt;/div&gt;&lt;!-- END text-1 --&gt;
        &lt;div id=&quot;text-2&quot;&gt;
            &lt;h1&gt;What is Parallax Scrolling?&lt;/h1&gt;
            &lt;p&gt;Parallax scrolling is a special scrolling technique in computer graphics, wherein background images move by the camera slower than foreground images, creating an illusion of depth in a 2D video game and adding to the immersion. The technique grew out of the multiplane camera technique used in traditional animation since the 1940s, and was popularized in the 1982 arcade game Moon Patrol.&lt;/p&gt;
        &lt;/div&gt;&lt;!-- END text-2 --&gt;
        &lt;div id=&quot;text-3&quot;&gt;
            &lt;h1&gt;Example of Parallax Scrolling?&lt;/h1&gt;
            &lt;p&gt;As you scroll up / scroll down the page, all the objects are animated independently of one another to create an illusion of depth.&lt;/p&gt;
        &lt;/div&gt;&lt;!-- END text-3 --&gt;
    &lt;/div&gt;&lt;!-- END text --&gt;
    
    &lt;div class=&quot;bg3&quot;&gt;
    	&lt;img class=&quot;bg3-1&quot; src=&quot;pink.png&quot; width=&quot;370&quot; height=&quot;370&quot; /&gt;
        &lt;img class=&quot;bg3-2&quot; src=&quot;blue.png&quot; width=&quot;370&quot; height=&quot;370&quot; /&gt;
        &lt;img class=&quot;bg3-3&quot; src=&quot;green.png&quot; width=&quot;370&quot; height=&quot;370&quot; /&gt;
    &lt;/div&gt;&lt;!-- END bg3 --&gt;
    
    &lt;div class=&quot;bg2&quot;&gt;
    	&lt;img class=&quot;bg2-1&quot; src=&quot;cloud-big.png&quot; width=&quot;140&quot; height=&quot;65&quot; /&gt;
        &lt;img class=&quot;bg2-2&quot; src=&quot;cloud-big.png&quot; width=&quot;140&quot; height=&quot;65&quot; /&gt;
        &lt;img class=&quot;bg2-3&quot; src=&quot;cloud-big.png&quot; width=&quot;140&quot; height=&quot;65&quot; /&gt;
        &lt;img class=&quot;bg2-4&quot; src=&quot;cloud-big.png&quot; width=&quot;140&quot; height=&quot;65&quot; /&gt;
    &lt;/div&gt;&lt;!-- END bg2 --&gt;
    
    &lt;div class=&quot;bg1&quot;&gt;
    	&lt;img class=&quot;bg1-1&quot; src=&quot;cloud-medium.png&quot; width=&quot;86&quot; height=&quot;40&quot; /&gt;
        &lt;img class=&quot;bg1-2&quot; src=&quot;cloud-medium.png&quot; width=&quot;86&quot; height=&quot;40&quot; /&gt;
        &lt;img class=&quot;bg1-3&quot; src=&quot;cloud-medium.png&quot; width=&quot;86&quot; height=&quot;40&quot; /&gt;
        &lt;img class=&quot;bg1-4&quot; src=&quot;cloud-medium.png&quot; width=&quot;86&quot; height=&quot;40&quot; /&gt;
    &lt;/div&gt;&lt;!-- END bg1 --&gt;
&lt;/div&gt;&lt;!-- END parallax_wrapper --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>The CSS</h3>
<p>There are 2 important CSS properties that we are going to use for creating illusion of depth for our page, which is <strong>position</strong> and <strong>z-index</strong>. Following is how our CSS code looks like:</p>
<pre class="brush: css; title: ; notranslate">
&lt;style&gt;
body {
	background: #def0fa;
	color: #333;
	font-family:Arial, Helvetica, sans-serif;
	font-size: 24px;
	line-height: 1.65;
}

h1 {
	color: #2A6360;
	font-family: Georgia, &quot;Times New Roman&quot;, Times, serif;
	font-size: 60px;
	font-weight: normal;
	line-height: 1.3;
}

/*Content*/
.text {
	z-index: 4;
	position: relative;
	width: 940px;
	margin: 0 auto;
}

.text div {
	padding: 100px 0;
	width: 500px;
}

/*Image Object*/
.bg3 {
	z-index: 3;
	position: fixed;
	left: 55%; /* align left edge with center of viewport */
	top: 0;
	width: 940px;
}

	.bg3-1 {
		position: absolute;
		top: 150px;	
	}
	
	.bg3-2 {
		position: absolute;
		top: 750px;	
	}
	
	.bg3-3 {
		position: absolute;
		top: 1350px;	
	}

/*Big Cloud*/
.bg2 {
	z-index: 2;
	position: fixed;
	top: 0;
	width: 940px;
}

	.bg2-1 {
			position: absolute;
			top: 200px;
			left: 500px;
	}
	
	.bg2-2 {
			position: absolute;
			top: 840px;
			left: 250px;
	}
	
	.bg2-3 {
			position: absolute;
			top: 460px;
			left: 130px;
	}
	
	.bg2-4 {
			position: absolute;
			top: 580px;
			left: 850px;
	}

/*Medum Cloud*/
.bg1 {
	z-index: 1;
	position: fixed;
	top: 0;
	width: 940px;
}

	.bg1-1 {
			position: absolute;
			top: 68px;
			left: 230px;
	}
	
	.bg1-2 {
			position: absolute;
			top: 540px;
			left: 750px;
	}
	
	.bg1-3 {
			position: absolute;
			top: 660px;
			left: 630px;
	}
	
	.bg1-4 {
			position: absolute;
			top: 720px;
			left: 287px;
	}
&lt;/style&gt;
</pre>
<p>As you see above, we use z-index to control the parallax effect.</p>
<p>Within each individual main layers elements are absolutely positioned. We can arrange the content in different ways according to the topic of the section.</p>
<h3>The JavaScript</h3>
<p>Ok, here is the section for us to apply some magic to our page. <img src='http://www.onlywebpro.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(function() {
	$(window).bind('scroll',function(e){
    parallaxScroll();
});
 
function parallaxScroll(){
    var scrolled = $(window).scrollTop();
    $('.bg1').css('top',(0-(scrolled*.25))+'px');
    $('.bg2').css('top',(0-(scrolled*.5))+'px');
    $('.bg3').css('top',(0-(scrolled*.75))+'px');
}						   
});
&lt;/script&gt;
</pre>
<p>First of all, what we need to do is to bind a scroll event to the window object. Next, we tell the browser to run a function with named &#8220;<strong>parallaxScroll</strong>&#8221; when user scrolls down or up. Then inside the <strong>parallaxScroll</strong> function,  we get the current vertical position of the scroll bar by using <strong>.scrollTop()</strong> API, and use it for the calculation of layer&#8217;s position. So that, the foreground layer is always aligned to the top of the document, while the movement of other layers is adjusted according to their depth.</p>
<p>Save your document and view it on web browser.</p>
<p><a href="http://www.onlywebpro.com/demo/jquery/parallax/parallax.html" target="_blank" class="demo_btn">View Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2013/01/28/develop-a-jquery-parallax-scrolling-framework/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create HTML5 Canvas Drawing Board Within 5 Minutes!</title>
		<link>http://www.onlywebpro.com/2013/01/10/create-html5-canvas-drawing-board-within-5-minutes/</link>
		<comments>http://www.onlywebpro.com/2013/01/10/create-html5-canvas-drawing-board-within-5-minutes/#comments</comments>
		<pubDate>Thu, 10 Jan 2013 01:50:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2760</guid>
		<description><![CDATA[A tutorial on how to create a drawing board using HTML5 Canvas API.]]></description>
				<content:encoded><![CDATA[<p>Welcome to &#8220;Create HTML5 Canvas Drawing Board Within 5 Minutes!&#8221; tutorial. We are going to create a drawing board using HTML5 Canvas API. This is an easy to follow tutorial, and I’ll try not to lose anyone, though, I promise. If you&#8217;re not entirely sure what HTML5 Canvas is, please read <a href="http://www.onlywebpro.com/2011/06/25/html5-canvas-for-absolute-beginners-part-1/" title="HTML5 Canvas For Absolute Beginners" target="_blank">HTML5 Canvas For Absolute Beginners</a>, before you continuing this tutorial.</p>
<p>Please check out the demo before we start our tutorial.</p>
<p><a href="http://www.onlywebpro.com/demo/gamedev/canvas_drawing_board.html" target="_blank" class="demo_btn">View Demo</a></p>
<h3>HTML Structure</h3>
<p>Ok, let&#8217;s start our tutorial by creating a div named &#8220;<strong>board</strong>&#8221; which will contains a canvas element and a color picker dropdown box. The canvas element will contains an id named &#8220;<strong>myCanvas</strong>&#8221; and 500px as value for its height and width property; Same to the color picker dropdown box, each child elements of color picker dropdown box contains an id, which allows us to access it later via JavaScript.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;HTML5 Canvas Drawing Board | onlyWebPro.com&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;board&quot;&gt;
&lt;canvas id=&quot;myCanvas&quot; width=&quot;500px&quot; height=&quot;500px&quot;&gt;
	Sorry, your browser doesn't support canvas technology.
&lt;/canvas&gt;
&lt;p&gt;Color picker: &lt;select id=&quot;selectColor&quot;&gt;
		  &lt;option id=&quot;colBlack&quot; value=&quot;black&quot; selected=&quot;selected&quot;&gt;Black&lt;/option&gt;
		  &lt;option id=&quot;colRed&quot; value=&quot;red&quot;&gt;Red&lt;/option&gt;
		  &lt;option id=&quot;colBlue&quot; value=&quot;blue&quot;&gt;Blue&lt;/option&gt;
		  &lt;option id=&quot;colGreen&quot; value=&quot;green&quot;&gt;Green&lt;/option&gt;
		  &lt;option id=&quot;colOrange&quot; value=&quot;orange&quot;&gt;Orange&lt;/option&gt;
		  &lt;option id=&quot;colYellow&quot; value=&quot;yellow&quot;&gt;Yellow&lt;/option&gt;
&lt;/select&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;!-- END board --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>CSS Styles</h3>
<p>The CSS for this tutorial is simple and easy, following is how the CSS codes looks like:</p>
<pre class="brush: css; title: ; notranslate">
&lt;style&gt;
body {
	margin: 0;	
}

#board {
	margin: 0 auto;
	width: 500px;	
}

#myCanvas {
	border: 3px dotted #000;	
}
&lt;/style&gt;
</pre>
<p>First of all, we have to offset the body&#8217;s margin;  horizontally center the div with named &#8220;board&#8221;; and apply 3px width of border to the canvas element.</p>
<h3>The JavaScript</h3>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/JavaScript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=1.4.2&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	window.onload = function() {
		var myCanvas = document.getElementById(&quot;myCanvas&quot;);
		var curColor = $('#selectColor option:selected').val();
		if(myCanvas){
				var isDown 	= false;
				var ctx = myCanvas.getContext(&quot;2d&quot;);
				var canvasX, canvasY;
				ctx.lineWidth = 5;
				
				$(myCanvas)
				.mousedown(function(e){
						isDown = true;
						ctx.beginPath();
						canvasX = e.pageX - myCanvas.offsetLeft;
						canvasY = e.pageY - myCanvas.offsetTop;
						ctx.moveTo(canvasX, canvasY);
				})
				.mousemove(function(e){
						if(isDown != false) {
							canvasX = e.pageX - myCanvas.offsetLeft;
							canvasY = e.pageY - myCanvas.offsetTop;
							ctx.lineTo(canvasX, canvasY);
							ctx.strokeStyle = curColor;
							ctx.stroke();
						}
				})
				.mouseup(function(e){
						isDown = false;
						ctx.closePath();
				});
		}
		
		$('#selectColor').change(function () {
				curColor = $('#selectColor option:selected').val();
		});
		
	};
&lt;/script&gt;
</pre>
<p>Here is the section where we convert our canvas into a drawing board. First of all, please include the jQuery library into our HTML document. You can either download the library from <a href="http://jquery.com/" title="jQuery Library" target="_blank">jquery.com</a> or use <a href="https://developers.google.com/speed/libraries/devguide#jquery" title="Google Hosted jQuery Library" target="_blank">Google hosted jQuery library</a>.</p>
<p>Next, we will have a <strong>window.onload</strong> event to executes all the codes when the window has loaded. We will check whether the canvas element is exist or supported by the browser or not, if yes then our canvas will start listen to the user&#8217;s mouse activity via &#8220;<strong>mousedown</strong>&#8220;, &#8220;<strong>mousemove</strong>&#8221; and &#8220;<strong>mouseup</strong>&#8221; events.</p>
<p>As you can seen above, there is a variable called &#8220;<strong>isDown</strong>&#8220;. This variable is used to store the current status of the mouse click. The boolean value of &#8220;isDown&#8221; variable is set to TRUE when the mouse click is down and will set to FALSE when the mouse click is up. Besides that, we also prepare a variable called &#8220;<strong>curColor</strong>&#8221; to store the color that picked by the user using color picker dorpdown box.</p>
<p>Save your document, run it in canvas supported browser and start to draw something on your canvas drawing board!</p>
<p><a href="http://www.onlywebpro.com/demo/gamedev/canvas_drawing_board.html" target="_blank" class="demo_btn">View Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2013/01/10/create-html5-canvas-drawing-board-within-5-minutes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML5 Storage: IndexedDB (Simple Easy to Understand)</title>
		<link>http://www.onlywebpro.com/2012/12/23/html5-storage-indexeddb/</link>
		<comments>http://www.onlywebpro.com/2012/12/23/html5-storage-indexeddb/#comments</comments>
		<pubDate>Sun, 23 Dec 2012 01:44:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2696</guid>
		<description><![CDATA[A new HTML5 web database that allows our HTML5 web application to store data inside a user's browser.]]></description>
				<content:encoded><![CDATA[<div class="yellow_note">Please note: This only works as intended in browsers that support the  HTML5 IndexedDB API. Browser compatibility: Firefox 16 onwards, IE 10 and Chrome 12 onwards</div>
<h3>What is IndexedDB?</h3>
<p>The IndexedDB Database or better known it as <strong>IndexedDB</strong>, a new HTML5 web database that allows our HTML5 web application to store data inside a user&#8217;s browser. Unlike <strong>HTML5 localstorage</strong> which lets us store data using a simple key-value pair only, the IndexedDB is more powerful and useful for applications that requires to store a large amount of data. In addition, with its rich queries abilities, these applications can load faster and more responsive than ever.</p>
<h3>Why Using IndexedDB?</h3>
<p>The W3C has announced that the Web SQL database (another option of HTML5 storage) is a deprecated specification, and web developers should not use the technology anymore. Instead, web developers should use the replacement &#8211; <strong>IndexedDB</strong>, a new HTML5 data storage to manipulate their data on client-side.</p>
<h3>The Key Concept of IndexedDB</h3>
<ul>
<li><strong>IndexedDB is NOT same as a Relational Database</strong>: Please keep in mind that IndexedDB is Object-Oritend, which differs from relational database. This important and fundamental difference affects the way you design and build your applications.</li>
<li><strong>IndexedDB store key-value pairs</strong>: The value is an object that can have 1 or more properties. The key can be based on a key generator or derived by a key path that defines the path to the key value.</li>
<li><strong>The IndexedDB API is mostly asynchronous</strong>: Tha API doesn&#8217;t return any values, instead we need a callback function to get the returning data.</li>
<li><strong>IndexedDB does not use Structured Query Language (SQL):</strong> It uses queries on an index that produces a cursor, which you use to iterate across the result set.</li>
<li><strong>IndexedDB prevents applications from accessing data with a different origin:</strong> You can only retrieve the data from the same origin (domain / port).</li>
</ul>
<h3>The Outline of This Article</h3>
<p>Following decribes exactly what you will learn in this article:</p>
<ul>
<li>Open a database and start the transaction.</li>
<li>Create an object store.</li>
<li>Record and read data.</li>
<li>Listen to the DOM event.</li>
<li>Display the data(result) from the indexedDB</li>
</ul>
<div class="yellow_note"><strong>*</strong>Here is an important message for you, the IndexedDB is still an experimental technology, and this technology is not yet solidified at the moment, so every browser vendors may have different implementations of the IndexedDB API.</div>
<p>Please check out the demo before we start the tutorial.</p>
<p><a href="http://www.onlywebpro.com/demo/jquery/indexeddb.html" target="_blank" class="demo_btn">View Demo</a></p>
<h3>Get Started</h3>
<p>Since we know that the IndexedDB API is still evolve, so we need to include the following prefixes of implementation. Besides, for best practice, we should always provide fallback content for unsupported browsers.</p>
<pre class="brush: jscript; title: ; notranslate">
//prefixes of implementation that we want to test
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;

//prefixes of window.IDB objects
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange

if (!window.indexedDB) {
    window.alert(&quot;Your browser doesn't support a stable version of IndexedDB.&quot;)
}
</pre>
<h3>Opening an IndexedDB Database</h3>
<p>Before we create the database, the very first thing to do is to prepare some data for the database. Let say we have some customer information as shown below:</p>
<pre class="brush: jscript; title: ; notranslate">
const customerData = [
  { id: &quot;00-01&quot;, name: &quot;Bill&quot;, age: 35, email: &quot;bill@company.com&quot; },
  { id: &quot;00-02&quot;, name: &quot;Donna&quot;, age: 32, email: &quot;donna@home.org&quot; }
];

</pre>
<p>2 data enetries, each entry consists of the information of ID, name, age and email of the customer.</p>
<p>Before we can insert the data into the database, we need to open our database using the <strong>open()</strong> method as shown below:</p>
<pre class="brush: jscript; title: ; notranslate">
var db;
var request = window.indexedDB.open(&quot;newDatabase&quot;, 1);

request.onerror = function(event) {
  console.log(&quot;error: &quot;);
};

request.onsuccess = function(event) {
  db = request.result;
  console.log(&quot;success: &quot;+ db);
};

request.onupgradeneeded = function(event) {

}
</pre>
<p>As you can see we have opened a database with the name &#8220;<strong>newDatabase</strong>&#8221; and the version of the database.  All IndexedDB databases are stored in the same origin with the web application / website. Example, if myblog.com might has a database named &#8220;newDatabase&#8221; and mybusiness.com also might has a totally distinct database named &#8220;newDatabase&#8221;.</p>
<p>The open() method has accepts <strong>2 parameters</strong>, the first is the name ofthe database. It will checks whether the database named &#8220;newDatabase&#8221; is already exist or not, if it is exist, then it will open the database, else it will create a new one. The second paramter of open() method is the version of the database, which allows you to update the schema of the database.</p>
<h4>Onsuccess handler</h4>
<p>If everything succeeds, then a success event &#8220;<strong>onsuccess</strong>&#8221; is fired with request as its target and we have save the request&#8217;s result for later use by assigning it to <strong>db </strong>variable.</p>
<h4>Onerror handler</h4>
<p>If the process of opening database fail, then an error event &#8220;<strong>onerror</strong>&#8221; is fired.</p>
<h4>Onupgradeneeded handler</h4>
<p>If you want to update the database, or to create, delete or modify the database, then you have to implement the onupgradeneeded handler or which will be called as part of a <strong>versionchange </strong>transaction that allows you to make any changes on the database. Please bear in mind that, the &#8220;<strong>onupgradeneeded</strong>&#8221; handler is the only place for you to alter the structure of database.</p>
<h3>Structuring the Database</h3>
<p>Again, IndexedDB is <strong>NOT </strong>same as a Relational Database. IndexedDB uses object stores to store data rather than tables. Whenever a value is stored in an object store, it is associated with a key. The interesting of IndexedDB is it allows us to create indices on any object store. An index lets us to access the values stored in object store using the value of a property of the stored object. This may sound confusing now, but you may know it better after go through the entire lesson.</p>
<p>The following code illustrates how we create the object store and insert the pre-prepared data into it:</p>
<pre class="brush: jscript; title: ; notranslate">
request.onupgradeneeded = function(event) {
	var db = event.target.result;
	var objectStore = db.createObjectStore(&quot;customers&quot;, {keyPath: &quot;id&quot;});
	for (var i in customerData) {
		objectStore.add(customerData[i]);	
	}
}
</pre>
<p>We create an object store using <strong>createObjectStore()</strong> method. This method accepts 2 parameters: &ndash; name of the store and a parameter object. In this case, we have named the object store as &#8220;customers&#8221; and defined a keyPath that is the property that makes an individual object in the store unique. In this example, we have use the &#8220;id&#8221; as keyPath, which is unique value in the object store, and you must make sure that the &#8220;id&#8221; property must be present in every objects in the object store.</p>
<p>Once the object store is created, we can start adding the data into it using <strong>for </strong>loop.</p>
<h3>Manually Adding Data</h3>
<p>You may probably want to manually add extra data into the database, then here is how you should write the function:</p>
<pre class="brush: jscript; title: ; notranslate">
function add() {
	var request = db.transaction([&quot;customers&quot;], &quot;readwrite&quot;)
                .objectStore(&quot;customers&quot;)
                .add({ id: &quot;00-03&quot;, name: &quot;Kenny&quot;, age: 19, email: &quot;kenny@planet.org&quot; });
				
	request.onsuccess = function(event) {
	  	alert(&quot;Kenny has been added to your database.&quot;);
	};
	
	request.onerror = function(event) {
		alert(&quot;Unable to add data\r\nKenny is aready exist in your database! &quot;);	
	}
	
}
</pre>
<p>We have just manually added a new data named with &#8220;Kenny&#8221; to the object store &#8220;customer&#8221; using <strong>add()</strong> method.</p>
<p>Before we can do anything (read, write, modify) to our database, we have to start use a <strong>transaction</strong>. The transaction() method is used to specify which object stores you want the transaction to span. The transaction() mthod accepts 3 parameters (second and third are optional): &ndash; First is the list of object store you want to deal with, second is whether you want to read only or read and write to the object, third is the versionchange.</p>
<p>The transaction method let you have the object store that you specified and insert, modify or delete the data that you need. In this case, we insert the data using <strong>add()</strong> method.</p>
<h3>Retrieving Data</h3>
<p>Let&#8217;s retrieve the data from the database. We can retrieve the data using <strong>get()</strong> method.</p>
<pre class="brush: jscript; title: ; notranslate">
function read() {
	var transaction = db.transaction([&quot;customers&quot;]);
	var objectStore = transaction.objectStore(&quot;customers&quot;);
	var request = objectStore.get(&quot;00-03&quot;);
	request.onerror = function(event) {
	  alert(&quot;Unable to retrieve daa from database!&quot;);
	};
	request.onsuccess = function(event) {
	  // Do something with the request.result!
	  if(request.result) {
	  	alert(&quot;Name: &quot; + request.result.name + &quot;, Age: &quot; + request.result.age + &quot;, Email: &quot; + request.result.email);
	  } else {
		alert(&quot;Kenny couldn't be found in your database!&quot;);  
	  }
	};
}
</pre>
<p>We use <strong>get()</strong> method to retrieve the data we need from object store. Since we already set the id of object as keyPath earlier, so the get() method will look up the object that has the same id value. This will return us the object named &#8220;Kenny&#8221;which is the object that we manually added in the previous function.</p>
<h4>Retrieving All Data</h4>
<p>If you want get all data instead of one from object store, then you may need to use a <strong>cursor</strong>. Here is another function that using cursor to retrieve all data from object store: </p>
<pre class="brush: jscript; title: ; notranslate">
function readAll() {
	var objectStore = db.transaction(&quot;customers&quot;).objectStore(&quot;customers&quot;);
 
	objectStore.openCursor().onsuccess = function(event) {
	  var cursor = event.target.result;
	  if (cursor) {
		alert(&quot;Name for id &quot; + cursor.key + &quot; is &quot; + cursor.value.name + &quot;, Age: &quot; + cursor.value.age + &quot;, Email: &quot; + cursor.value.email);
		cursor.continue();
	  }
	  else {
		alert(&quot;No more entries!&quot;);
	  }
	};	
}
</pre>
<p>As you can see, we implement the <strong>openCursor()</strong> method to accomplish the goal. The openCursor() is used to iterate over multiple records in a database. It can accepts several parameters, such as limit the range items, the direction that we want to iterate and etc. In this case, we leave it no parameters.</p>
<p>The cursor object itself is the result of the request. We have implement the <strong>continue()</strong> function to continues with the next iteration in the loop. When the loop reached end, then we will get the alert with content &#8220;No more entries!&#8221;.</p>
<h3>Removing Data</h3>
<p>Removing data from object store is very similar to other functions that we have just learnt. Here is how the code looks like:</p>
<pre class="brush: jscript; title: ; notranslate">
function remove() {

	var request = db.transaction([&quot;customers&quot;], &quot;readwrite&quot;)
                .objectStore(&quot;customers&quot;)
                .delete(&quot;00-03&quot;);
	request.onsuccess = function(event) {
	  alert(&quot;Kenny's entry has been removed from your database.&quot;);
	};
}
</pre>
<p>If you want to remove data from object store, then you may need to use <strong>delete()</strong> method. You have to pass the keyPath of the object that you want to remove as paramter to the delete() method. In this case, we remove the object with named &#8220;Kenny&#8221; which we added via add function just now.</p>
<h3>The HTML</h3>
<p>We have just wrote all the functions, and now is the time to display the data using the onclick event that binded to HTML button.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;IndexedDb Demo | onlyWebPro.com&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;button onclick=&quot;read()&quot;&gt;Read single data from indexedDb&lt;/button&gt;
&lt;button onclick=&quot;readAll()&quot;&gt;Read all data from indexedDb&lt;/button&gt;
&lt;button onclick=&quot;add()&quot;&gt;Add data to indexedDb&lt;/button&gt;
&lt;button onclick=&quot;remove()&quot;&gt;Delete data from indexedDb&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>We have prepared 4 HTML buttons. Each of the button is used to trigger the Javascript function that we wrote earlier in this article. Save your document and view it in supported browser. Have fun! <img src='http://www.onlywebpro.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>The Final Code</h3>
<pre class="brush: jscript; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;IndexedDb Demo | onlyWebPro.com&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
//prefixes of implementation that we want to test
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;

//prefixes of window.IDB objects
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange

if (!window.indexedDB) {
    window.alert(&quot;Your browser doesn't support a stable version of IndexedDB.&quot;)
}

const customerData = [
  { id: &quot;00-01&quot;, name: &quot;Bill&quot;, age: 35, email: &quot;bill@company.com&quot; },
  { id: &quot;00-02&quot;, name: &quot;Donna&quot;, age: 32, email: &quot;donna@home.org&quot; }
];


var db;
var request = window.indexedDB.open(&quot;newDatabase&quot;, 1);

request.onerror = function(event) {
  console.log(&quot;error: &quot;);
};

request.onsuccess = function(event) {
  db = request.result;
  console.log(&quot;success: &quot;+ db);
};

request.onupgradeneeded = function(event) {
	var db = event.target.result;
	var objectStore = db.createObjectStore(&quot;customers&quot;, {keyPath: &quot;id&quot;});
	for (var i in customerData) {
		objectStore.add(customerData[i]);	
	}
}

function read() {
	var transaction = db.transaction([&quot;customers&quot;]);
	var objectStore = transaction.objectStore(&quot;customers&quot;);
	var request = objectStore.get(&quot;00-03&quot;);
	request.onerror = function(event) {
	  alert(&quot;Unable to retrieve daa from database!&quot;);
	};
	request.onsuccess = function(event) {
	  // Do something with the request.result!
	  if(request.result) {
	  	alert(&quot;Name: &quot; + request.result.name + &quot;, Age: &quot; + request.result.age + &quot;, Email: &quot; + request.result.email);
	  } else {
		alert(&quot;Kenny couldn't be found in your database!&quot;);  
	  }
	};
}

function readAll() {
	var objectStore = db.transaction(&quot;customers&quot;).objectStore(&quot;customers&quot;);
 
	objectStore.openCursor().onsuccess = function(event) {
	  var cursor = event.target.result;
	  if (cursor) {
		alert(&quot;Name for id &quot; + cursor.key + &quot; is &quot; + cursor.value.name + &quot;, Age: &quot; + cursor.value.age + &quot;, Email: &quot; + cursor.value.email);
		cursor.continue();
	  }
	  else {
		alert(&quot;No more entries!&quot;);
	  }
	};	
}

function add() {
	var request = db.transaction([&quot;customers&quot;], &quot;readwrite&quot;)
                .objectStore(&quot;customers&quot;)
                .add({ id: &quot;00-03&quot;, name: &quot;Kenny&quot;, age: 19, email: &quot;kenny@planet.org&quot; });
				
	request.onsuccess = function(event) {
	  	alert(&quot;Kenny has been added to your database.&quot;);
	};
	
	request.onerror = function(event) {
		alert(&quot;Unable to add data\r\nKenny is aready exist in your database! &quot;);	
	}
	
}

function remove() {

	var request = db.transaction([&quot;customers&quot;], &quot;readwrite&quot;)
                .objectStore(&quot;customers&quot;)
                .delete(&quot;00-03&quot;);
	request.onsuccess = function(event) {
	  alert(&quot;Kenny's entry has been removed from your database.&quot;);
	};
}

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;button onclick=&quot;read()&quot;&gt;Read single data from indexedDb&lt;/button&gt;
&lt;button onclick=&quot;readAll()&quot;&gt;Read all data from indexedDb&lt;/button&gt;
&lt;button onclick=&quot;add()&quot;&gt;Add data to indexedDb&lt;/button&gt;
&lt;button onclick=&quot;remove()&quot;&gt;Delete data from indexedDb&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><a href="http://www.onlywebpro.com/demo/jquery/indexeddb.html" target="_blank" class="demo_btn">View Demo</a></p>
<h3>Conclusion</h3>
<p>The HTML5 IndexedDB API is very useful and powerful. You can leverage it to create rich, online and offline HTML5 application. In addition, with IndexedDB API, you can cache data to make traditional web applications especially mobile web applications load faster and more responsive without need to retrieve data from the web server each time. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2012/12/23/html5-storage-indexeddb/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Animating Sprites In HTML5 Canvas</title>
		<link>http://www.onlywebpro.com/2012/10/05/animating-sprites-in-html5-canvas/</link>
		<comments>http://www.onlywebpro.com/2012/10/05/animating-sprites-in-html5-canvas/#comments</comments>
		<pubDate>Fri, 05 Oct 2012 13:15:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2562</guid>
		<description><![CDATA[In this article, we will introduce HTML5 Canvas animation and walks you through creating an animation of character walking.]]></description>
				<content:encoded><![CDATA[<p>When you want to build your own web games using the HTML5 Canvas element, you will need to find a way to handle your sprites animation. In this article, we will introduce HTML5 Canvas animation and walks you through creating an animation of character walking.</p>
<p><a href="http://www.onlywebpro.com/demo/gamedev/canvas-sprites-animation.html" target="_blank" class="demo_btn">View Demo</a></p>
<p>If you are new to HTML5 Canvas element, I suggest you to read this article first &#8220;<a href="http://www.onlywebpro.com/2011/06/25/html5-canvas-for-absolute-beginners-part-1/" title="HTML5 Canvas For Absolute Beginners " target="_blank">HTML5 Canvas For Absolute Beginners</a>&#8220;.</p>
<p>We are going to use the following PNG file as source of our sprite sequence:</p>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/12/sprite.png" alt="sprite" title="sprite" width="100" height="500" class="alignnone size-full wp-image-2594" /><br />
<em>PNG sprite sequence</em></p>
<h3>HTML5 Structure</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
    &lt;head&gt;
    	&lt;meta charset=&quot;UTF-8&quot; /&gt;
        &lt;title&gt;Animating Sprites In HTML5 Canvas | onlyWebPro.com&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;canvas id=&quot;myCanvas&quot; width=&quot;100&quot; height=&quot;100&quot;&gt;
            &lt;!-- Insert fallback content here --&gt;
            Sorry, your browser doesn't support canvas technology
        &lt;/canvas&gt;
        &lt;script&gt;
			//Script goes here
		&lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>We will create a canvas for displaying our sprites and set the width, height of the canvas to 100px. Please bear in mind that, the width and height of each frame of the PNG sprite sequence is 100 pixel:</p>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/12/animated_sprites_description.jpg" alt="animated_sprites_description" title="animated_sprites_description" width="568" height="262" class="alignnone size-full wp-image-2600" /></p>
<p>Besides, please remember to assign an id for our canvas element. For this case, we named it as &#8220;<strong>myCanvas</strong>&#8220;.</p>
<p>And that’s all for the HTML structure! Now, let’s take a look at the JavaScript section.</p>
<h3>JavaScript</h3>
<pre class="brush: jscript; title: ; notranslate">
&lt;script&gt;
	var width = 100,
		height = 100,
		frames = 4,
		
		currentFrame = 0,
		
		canvas = document.getElementById(&quot;myCanvas&quot;);
		ctx = canvas.getContext(&quot;2d&quot;);
		image = new Image()
		image.src = 'sprite.png';
	
	var draw = function(){
		ctx.clearRect(0, 0, width, height);
		ctx.drawImage(image, 0, height * currentFrame, width, height, 0, 0, width, height);
	
		if (currentFrame == frames) {
		  currentFrame = 0;
		} else {
		  currentFrame++;
		}
	}
	
	setInterval(draw, 100);
&lt;/script&gt;
</pre>
<p>As you seen above, the first thing we do in JavaScript section is to define the variables:</p>
<ul>
<li><strong>width:</strong> The width of the canvas.</li>
<li><strong>height:</strong> The height of the canvas.</li>
<li><strong>frames:</strong> The total frames of the animated sprites.</li>
<li><strong>currentFrame:</strong> The current frame of the animated sprites.</li>
<li><strong>canvas:</strong> For accessing the rendering context element.</li>
<li><strong>ctx:</strong> Render canvas&#8217;s context in 2D format.</li>
<li><strong>image:</strong> A variable to hold our PNG file.</li>
</ul>
<p>To animate the sprite, we need just display each frame of the sprite using <strong>drawImage()</strong> method. The drawImage() is a method that allow us to draw image or video onto canvas. Below is the syntax and parameters of drawImage():</p>
<pre class="brush: jscript; title: ; notranslate">
context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
</pre>
<table>
<tbody>
<tr>
<th align="left" width="15%">Parameter</th>
<th align="left" width="70%">Description</th>
</tr>
<tr>
<td>img</td>
<td>Specifies the image, canvas, or video element to use</td>
</tr>
<tr>
<td>sx</td>
<td>Optional parameter. The x coordinate where to start clipping</td>
</tr>
<tr>
<td>sy</td>
<td>Optional parameter. The y coordinate where to start clipping</td>
</tr>
<tr>
<td>swidth</td>
<td>Optional parameter. The width of the clipped image</td>
</tr>
<tr>
<td>sheight</td>
<td>Optional parameter. The height of the clipped image</td>
</tr>
<tr>
<td>x</td>
<td>The x coordinate where to place the image on the canvas</td>
</tr>
<tr>
<td>y</td>
<td>The y coordinate where to place the image on the canvas</td>
</tr>
<tr>
<td>width</td>
<td>Optional parameter. The width of the image to use (stretch or reduce the image)</td>
</tr>
<tr>
<td>height</td>
<td>Optional parameter. The height of the image to use (stretch or reduce the image)</td>
</tr>
</tbody>
</table>
<p>Next, we write a conditional statement to check if the currentFrame is less than total frames, then increment the currentFrame. The currentFrame is used to decide which frame of the sprite should we display on the canvas via drawImage() method.</p>
<p>Lastly, we use &#8220;<strong>setInterval()</strong>&#8221; to run the <strong>draw function</strong> every 100 milliseconds.</p>
<p>That&#8217;s it! Save your document and run it on supported browser!</p>
<h3>You may also like:</h3>
<ul>
<li><a href="http://www.onlywebpro.com/2011/06/25/html5-canvas-for-absolute-beginners-part-1/" title="HTML5 Canvas For Absolute Beginners " target="_blank">HTML5 Canvas For Absolute Beginners</a></li>
<li><a href="http://www.onlywebpro.com/2012/01/14/most-easiest-simplest-way-to-create-a-game-using-html5-canvas/">Most Easiest &amp; Simplest Way to Create a Game Using HTML5 Canvas</a></li>
<li><a href="http://www.onlywebpro.com/2012/01/28/game-development-mouse-and-touch-event-detection/">HTML5 Canvas Game Development Series</a></li>
<li><a href="http://www.onlywebpro.com/2012/08/18/showcase-of-10-awesome-html5-canvas-games/">Showcase Of 10 Awesome HTML5 Canvas Games</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2012/10/05/animating-sprites-in-html5-canvas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery Mobile for Absolute Beginners – Part 4</title>
		<link>http://www.onlywebpro.com/2012/09/17/jquery-mobile-for-absolute-beginners-part-4/</link>
		<comments>http://www.onlywebpro.com/2012/09/17/jquery-mobile-for-absolute-beginners-part-4/#comments</comments>
		<pubDate>Mon, 17 Sep 2012 02:05:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mobile Content]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2538</guid>
		<description><![CDATA[The Full Series Part 1: Introduction to jQuery Mobile &#38; Page Structure Part 2: Buttons, List Views, Dialogs &#38; Transitions Part 3: Form Elements Part 4: Touch Events Hi guys! Welcome to the part 4 of jQuery Mobile for Absolute Beginners. In this lesson,you will learn to create a simple interactive page using Touch Event [...]]]></description>
				<content:encoded><![CDATA[<div class="tutorial_details">
<h3>The Full Series</h3>
<ul>
<li><a href="http://www.onlywebpro.com/2012/06/29/jquery-mobile-for-absolute-beginners-part-1/">Part 1: Introduction to jQuery Mobile &amp; Page Structure</a></li>
<li><a href="http://www.onlywebpro.com/2012/07/15/jquery-mobile-for-absolute-beginners-part-2/">Part 2: Buttons, List Views, Dialogs &amp; Transitions</a></li>
<li><a href="http://www.onlywebpro.com/2012/08/31/jquery-mobile-for-absolute-beginners-part-3/">Part 3: Form Elements</a></li>
<li><a href="http://www.onlywebpro.com/2012/09/17/jquery-mobile-for-absolute-beginners-part-4/">Part 4: Touch Events</a></li>
</ul>
</div>
<p>Hi guys! Welcome to the part 4 of jQuery Mobile for Absolute Beginners.<strong> In this lesson,you will learn to create a simple interactive page using Touch Event provided by jQuery Mobile framework.</strong> If you haven’t already, be sure to read the previous articles of this series first!</p>
<h3>Touch Event in jQuery Mobile</h3>
<p>jQuery Mobile offers several touch events that allows user to interact with jQuery page that look and feel like native mobile application. Following is the list of touch events that we could use for our jQuery Mobile project.</p>
<ul>
<li><strong>tap:</strong> Tap event triggers after a quick, complete touch event.</li>
<li><strong>taphold:</strong> Tap Hold event triggers after a held complete touch event. By default, user must hold their tap for 750 milliseconds before the taphold event is fired on the target element.</li>
<li><strong>swipe:</strong> Swipe event triggers when a horizontal drag of 30px or more (and less than 75px vertically) occurs within 1 second duration.</li>
<li><strong>swipeleft:</strong> Swipe Left event triggers when users swipe from right to left on the target element.</li>
<li><strong>swiperight:</strong> Swipe Right event triggers when users swipe from left to right on the target element.</li>
</ul>
<h3>Creating An Interactive Page Using Touch Events</h3>
<p>Ok, let&#8217;s create an interactive page using the touch events that we just learned. The idea is to have a face illustration and reveal more facial expression when swipe &amp; tap hold on it. You can check out the demo before we proceed.</p>
<p><em>Note: Best viewed in iOS Safari &amp; Android browser.</em></p>
<p><a href="http://www.onlywebpro.com/demo/jquery/swipe.html" target="_blank" class="demo_btn">View Demo</a></p>
<hr />
<h4>HTML Structure</h4>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
	&lt;head&gt;
	&lt;title&gt;jQuery Mobile Touch Event Demo From onlyWebPro.com&lt;/title&gt;
	&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css&quot; /&gt;
	&lt;script src=&quot;http://code.jquery.com/jquery-1.7.1.min.js&quot;&gt;&lt;/script&gt;
	&lt;script src=&quot;http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div data-role=&quot;page&quot;&gt;
	&lt;div data-role=&quot;header&quot;&gt;
		&lt;h1&gt;Interactive Facial Expression&lt;/h1&gt;
	&lt;/div&gt;&lt;!-- /header --&gt;

	&lt;div data-role=&quot;content&quot;&gt;
    	&lt;div class=&quot;swipe_area&quot;&gt;
            &lt;div id=&quot;pic&quot; class=&quot;front&quot;&gt;&lt;/div&gt;&lt;!-- END pic --&gt;
            &lt;p&gt;&lt;em&gt;Instruction:&lt;/em&gt;&lt;br /&gt;
            &lt;strong&gt;Swipe Left / Right&lt;/strong&gt; to change the facial expression.&lt;br /&gt;
            &lt;strong&gt;Tap &amp;amp; Hold&lt;/strong&gt; for a second to change back its original facial expression.&lt;/p&gt;
        &lt;/div&gt;&lt;!-- END swipe_area --&gt;
	&lt;/div&gt;&lt;!-- /content --&gt;

    &lt;div data-role=&quot;footer&quot;&gt;
		&lt;p&gt;&amp;copy; Copyright 2012 by onlyWebPro.com&lt;/p&gt;
	&lt;/div&gt;&lt;!-- /footer --&gt;
&lt;/div&gt;&lt;!-- /page --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>We will have a basic structure of jQuery Mobile Page where consists of header bar, content region and footer bar. Within the content region, we will have a division called &#8220;swipe_area&#8221; which contains a picture division and instruction. The picture divison contains class that gives us ability to control the facial expression using jQuery and CSS later.</p>
<h4>CSS Style</h4>
<pre class="brush: css; title: ; notranslate">
&lt;style&gt;
	#pic {background:url(swipe_pic.png) no-repeat -19px 0; width: 100px; height: 100px; margin: 0 auto;}
	#pic.front { background-position: -19px 0;}
	#pic.left { background-position: -127px 0;}
	#pic.right { background-position: -236px 0;}
	p { text-align: center; };
&lt;/style&gt;
</pre>
<p>We have given width and height for the picture division, and assign a CSS sprites (The facial expression graphic) as background image to it.</p>
<p>We have re-position the background image to just show the part of the image we need when user swipe left /swipe right / tap hold on the page.</p>
<h4>jQuery Code</h4>
<p>Here is the section where we make our page look lively.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script&gt;
	$(document).ready(function() {
		$('.swipe_area').bind('swipeleft', function(event) {
				$('#pic').removeClass().addClass('left');			
		});
		
		$('.swipe_area').bind('swiperight', function(event) {
				$('#pic').removeClass().addClass('right');			
		});
		
		$('.swipe_area').bind('taphold', function(event) {
				$('#pic').removeClass().addClass('front');			
		});
	});
&lt;/script&gt;
</pre>
<p>We have bind the <strong>swipeleft</strong>, <strong>swiperight </strong>and <strong>taphold </strong>events to the swipe_area division. If user is swipe the page from right to left, a new class &#8220;left&#8221; will be added to the picture holder; Conversely, if user is swipe the page from left to right, a new class &#8220;right&#8221; will be added to the picture holder.</p>
<p>To change back original facial expression, user is requires to tap and hold for a second for triggering taphold event.</p>
<p>That&#8217;s it! Save your document and view it in your smart devices!</p>
<h3>Conclusion</h3>
<p>You have just learned about the usage of Touch Events of jQuery Mobile. You know how to make your jQuery Mobile page lively by implementing touch events such as swipe left, swipe right and tap hold.</p>
<p>Stay tuned for more. <img src='http://www.onlywebpro.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2012/09/17/jquery-mobile-for-absolute-beginners-part-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JQuery Mobile for Absolute Beginners – Part 3</title>
		<link>http://www.onlywebpro.com/2012/08/31/jquery-mobile-for-absolute-beginners-part-3/</link>
		<comments>http://www.onlywebpro.com/2012/08/31/jquery-mobile-for-absolute-beginners-part-3/#comments</comments>
		<pubDate>Fri, 31 Aug 2012 02:56:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2498</guid>
		<description><![CDATA[Hi guys! Welcome to the part 3 of jQuery Mobile for Absolute Beginners. In this lesson, we will discuss on the form elements that used in jQuery Mobile.]]></description>
				<content:encoded><![CDATA[<div class="tutorial_details">
<h3>The Full Series</h3>
<ul>
<li><a href="http://www.onlywebpro.com/2012/06/29/jquery-mobile-for-absolute-beginners-part-1/">Part 1: Introduction to jQuery Mobile &amp; Page Structure</a></li>
<li><a href="http://www.onlywebpro.com/2012/07/15/jquery-mobile-for-absolute-beginners-part-2/">Part 2: Buttons, List Views, Dialogs &amp; Transitions</a></li>
<li><a href="http://www.onlywebpro.com/2012/08/31/jquery-mobile-for-absolute-beginners-part-3/">Part 3: Form Elements</a></li>
<li><a href="http://www.onlywebpro.com/2012/09/17/jquery-mobile-for-absolute-beginners-part-4/">Part 4: Touch Events</a></li>
</ul>
</div>
<p>Hi guys! Welcome to the part 3 of jQuery Mobile for Absolute Beginners. In this lesson, we will discuss on the form elements that used in jQuery Mobile. If you haven’t already, be sure to read the previous articles of this series first!</p>
<h3>Form in jQuery Mobile</h3>
<p>The jQuery Mobile automatically converts the HTML form elements into finger-friendly,  more attractive and useable on a mobile device. jQuery Mobile requires all form elements must be wrapped in a valid &lt;form&gt; tag that has an action and method, all form elements be paired with a meaningful label, and all form elements should have unique id across the pages in a site, and please keep in mind that, the form data submission for jQuery Mobile is automatically handled via AJAX.</p>
<h3>Text Input &amp; Textareas Element</h3>
<p>Constructing a text input or textarea in jQuery Mobile is same as you coded with standard HTML elements.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;form action=&quot;&quot; method=&quot;get&quot;&gt;
&lt;label for=&quot;basic&quot;&gt;Username:&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;&quot;  /&gt;

&lt;label for=&quot;remarks&quot;&gt;Textarea:&lt;/label&gt;
&lt;textarea name=&quot;remarks&quot; id=&quot;remarks&quot;&gt;&lt;/textarea&gt;
&lt;/form&gt;
</pre>
<h4>Outcome</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/text_input.jpg" alt="Text Input" title="Text Input" width="568" height="209" class="alignnone size-full wp-image-2515" /></p>
<p>This will produce a basic text input &amp; textarea with default styles, which set the width of the elements to 100%.</p>
<p>With jQuery Mobile, you can apply HTML5 input types such as password, email, number, tel into your input text elements. By specifying input types, mobile device users can speed up their data entry with specialized keyboard provided automatically by their browser. Example:</p>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/keyboard-types.jpg" alt="Specialized keyboard" title="Specialized keyboard" width="568" height="434" class="alignnone size-full wp-image-2526" /></p>
<p>If you want to visually group your text input elements, you can wrap the text input in a container with the <strong>data-role=&#8221;fieldcontain&#8221;</strong> attribute as shown below:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div data-role=&quot;fieldcontain&quot;&gt;
    &lt;label for=&quot;name&quot;&gt;Username:&lt;/label&gt;
    &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;&quot;  /&gt;
&lt;/div&gt;
</pre>
<h4>Outcome</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/text_input_field.jpg" alt="Group text input elements" title="Group text input elements" width="568" height="95" class="alignnone size-full wp-image-2516" /></p>
<p>Using <strong>data-role=&#8221;fieldcontain&#8221;</strong> attribute, aligns the input and associated label side-by-side, breaks and divide elements into 2 rows below 480px.</p>
<h3>Search Input Field</h3>
<p>By settings an text input as search input field, jQuery Mobile styles a text input with a magnified search icon and provides an &#8220;x&#8221; icon to clear the field once you start typing.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;label for=&quot;search&quot;&gt;Search:&lt;/label&gt;
&lt;input type=&quot;search&quot; name=&quot;search&quot; id=&quot;search&quot; value=&quot;&quot; /&gt;
</pre>
<h4>Outcome</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/search_field.jpg" alt="Search Input Field" title="Search Input Field" width="568" height="95" class="alignnone size-full wp-image-2517" /></p>
<h3>Select Menus</h3>
<p>jQuery Mobile leverages native OS option menu by default, which means when select menu is tapped, the native OS menu will open.</p>
<p>The framework also provide option for us to use custom-styled select menus instead of the native OS menu. To use custom-styled select menu, you just have to add <strong>data-native-menu=&#8221;false&#8221;</strong> attribute to your select menu.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;label for=&quot;select-menu&quot; class=&quot;select&quot;&gt;Select Menu:&lt;/label&gt;
&lt;select name=&quot;select-menu&quot; id=&quot;select-menu&quot;  data-native-menu=&quot;false&quot;&gt;
   &lt;option value=&quot;how&quot;&gt;How&lt;/option&gt;
   &lt;option value=&quot;are&quot;&gt;Are&lt;/option&gt;
   &lt;option value=&quot;you&quot;&gt;You?&lt;/option&gt;
&lt;/select&gt;
</pre>
<p>Then your select menu will become like this:</p>
<h4>Outcome</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/select_menu_custom.jpg" alt="Custom-styled select menus" title="Custom-styled select menus" width="568" height="209" class="alignnone size-full wp-image-2518" /></p>
<h3>Flip Toggle Switch</h3>
<p>The flip toggle switch is used for true or false data input. To construct a flip toggle switch, start with a select menu with ONLY 2 options and add <strong>data-role=&#8221;slider&#8221;</strong> to the select menu. Remember that? Flip toggle switch is used for true or false data input! So, the first option will be styled as &#8220;on&#8221; status and the second will be &#8220;off&#8221; status.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;label for=&quot;flip-switch&quot;&gt;Flip switch:&lt;/label&gt;
&lt;select name=&quot;flip-switch&quot; id=&quot;flip-switch&quot; data-role=&quot;slider&quot;&gt;
	&lt;option value=&quot;on&quot;&gt;True&lt;/option&gt;
	&lt;option value=&quot;off&quot;&gt;False&lt;/option&gt;
&lt;/select&gt; 
</pre>
<h4>Outcome</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/flip_switch.jpg" alt="Flip Toggle Switch" title="Flip Toggle Switch" width="568" height="105" class="alignnone size-full wp-image-2519" /></p>
<h3>Slider</h3>
<p>To use a slider in your jQuery Mobile page, add an input with the <strong>type=&#8221;range&#8221; attribute</strong>. The jQuery Mobile will automatically style and enhance the slider without any need to apply a data-role attribute.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;label for=&quot;slider&quot;&gt;Input slider:&lt;/label&gt;
&lt;input type=&quot;range&quot; name=&quot;slider&quot; id=&quot;slider&quot; value=&quot;20&quot; min=&quot;0&quot; max=&quot;100&quot; /&gt;
</pre>
<h4>Outcome</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/slider.jpg" alt="Slider" title="Slider" width="568" height="105" class="alignnone size-full wp-image-2520" /></p>
<p>There are some other attributes that you can use with slider such as:</p>
<ul>
<li><strong>step:</strong> To force the slider to snap to a specific increment.</li>
<li><strong>data-highlight:</strong> Have a highlight on the slider.</li>
</ul>
<p>Extras: If you like to find out more about constructing jQuery slider for desktop, please read our previous tutorial &#8211; <a href="http://www.onlywebpro.com/2012/02/15/build-a-jquery-range-slider-within-5-minutes/" title="Build A jQuery Range Slider Within 5 Minutes!" target="_blank">Build A jQuery Range Slider Within 5 Minutes!</a></p>
<h3>Checkboxes &amp; Radio Button</h3>
<p>To construct checkbox and radio button, you can write your code as same as standard HTML elements.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;label for=&quot;checkbox&quot;&gt;Windows&lt;/label&gt;
&lt;input type=&quot;checkbox&quot; name=&quot;checkbox&quot; id=&quot;checkbox&quot; /&gt;
&lt;label for=&quot;checkbox2&quot;&gt;Mac&lt;/label&gt;
&lt;input type=&quot;checkbox&quot; name=&quot;checkbox2&quot; id=&quot;checkbox2&quot; /&gt;

&lt;input type=&quot;radio&quot; name=&quot;radio-choice&quot; id=&quot;radio-choice-1&quot; value=&quot;choice-1&quot; checked=&quot;checked&quot; /&gt;
&lt;label for=&quot;radio-choice-1&quot;&gt;Car&lt;/label&gt;
&lt;input type=&quot;radio&quot; name=&quot;radio-choice&quot; id=&quot;radio-choice-2&quot; value=&quot;choice-2&quot;  /&gt;
&lt;label for=&quot;radio-choice-2&quot;&gt;Van&lt;/label&gt;
</pre>
<h4>Outcome</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/checkbox.jpg" alt="Checkboxes &amp; Radio Button" title="Checkboxes &amp; Radio Button" width="568" height="230" class="alignnone size-full wp-image-2521" /></p>
<p>For the radio button, the framework allow us to turn it into grouped button sets / tabs navigation where only a single button can be selected at once. To construct a tabs, what you need to do is just to wrap radio tag in a &lt;fieldset&gt; tag, add the <strong>data-role=&#8221;controlgroup&#8221;</strong> and the <strong>data-type=&#8221;horizontal&#8221;</strong> to the fieldset.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;fieldset data-role=&quot;controlgroup&quot; data-type=&quot;horizontal&quot; &gt; 
&lt;input type=&quot;radio&quot; name=&quot;radio-choice&quot; id=&quot;radio-choice-1&quot; value=&quot;choice-1&quot; checked=&quot;checked&quot; /&gt;
&lt;label for=&quot;radio-choice-1&quot;&gt;Car&lt;/label&gt;
&lt;input type=&quot;radio&quot; name=&quot;radio-choice&quot; id=&quot;radio-choice-2&quot; value=&quot;choice-2&quot;  /&gt;
&lt;label for=&quot;radio-choice-2&quot;&gt;Van&lt;/label&gt;
&lt;/fieldset&gt;
</pre>
<h4>Outcome</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/tabs.jpg" alt="Grouped button sets / tabs navigation" title="Grouped button sets / tabs navigation" width="568" height="74" class="alignnone size-full wp-image-2522" /></p>
<h3>Conclusion</h3>
<p>You have just learned about the usage and the attributes of form elements in jQuery Mobile. You know how the framework styles the element, and you also know when to use the element and how to use them with jQuery Mobile.</p>
<p>Stay tuned for more. <img src='http://www.onlywebpro.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2012/08/31/jquery-mobile-for-absolute-beginners-part-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JQuery Mobile for Absolute Beginners – Part 2</title>
		<link>http://www.onlywebpro.com/2012/07/15/jquery-mobile-for-absolute-beginners-part-2/</link>
		<comments>http://www.onlywebpro.com/2012/07/15/jquery-mobile-for-absolute-beginners-part-2/#comments</comments>
		<pubDate>Sun, 15 Jul 2012 09:36:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mobile Content]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2296</guid>
		<description><![CDATA[In this lesson, we will discuss on how the HTML5 data-* attributes that jQuery Mobile relies on to support various UI elements, transitions, and page structure.]]></description>
				<content:encoded><![CDATA[<div class="tutorial_details">
<h3>The Full Series</h3>
<ul>
<li><a href="http://www.onlywebpro.com/2012/06/29/jquery-mobile-for-absolute-beginners-part-1/">Part 1: Introduction to jQuery Mobile &amp; Page Structure</a></li>
<li><a href="http://www.onlywebpro.com/2012/07/15/jquery-mobile-for-absolute-beginners-part-2/">Part 2: Buttons, List Views, Dialogs &amp; Transitions</a></li>
<li><a href="http://www.onlywebpro.com/2012/08/31/jquery-mobile-for-absolute-beginners-part-3/">Part 3: Form Elements</a></li>
<li><a href="http://www.onlywebpro.com/2012/09/17/jquery-mobile-for-absolute-beginners-part-4/">Part 4: Touch Events</a></li>
</ul>
</div>
<p>Hi guys! Welcome to the second part of jQuery Mobile for Absolute Beginners. In this lesson, we will discuss on how the HTML5 data-* attributes that jQuery Mobile relies on to support various UI elements, transitions, and page structure. If you haven’t already, be sure to read the previous articles of this series first!</p>
<h3>Introduction to HTML5 data-* attributes</h3>
<p>The data-* attribute is a HTML5 elements that allow you to define and store arbitrary snippets of metadata for the sole purpose of making your JavaScript simpler. If you like to know more about the HTML5 data-* attributes, please read our previous article, to find out more. The jQuery Mobile uses the data-* attribute to transform basic markup into an enhanced and styled widget. Example, you are required to define the &#8220;data-role&#8221; for the header, body content and footer, when you are working with jQuery Mobile.</p>
<p>To learn more about HTML5 data-* attributes, please visit our previous article &#8211; <a href="http://www.onlywebpro.com/2012/06/16/a-complete-guide-of-using-html5-data-attributes/" title="A Complete Guide Of Using HTML5 Data Attributes (Data Set)" target="_blank">A Complete Guide Of Using HTML5 Data Attributes (Data Set)</a></p>
<p><strong>Supported data-* Syntax For jQuery Mobile.</strong><br />
Here is the supported list of data-* syntax that you should know when you are trying to transform your HTML markup into styled widget.</p>
<h3>Header, Body Content &amp; Footer</h3>
<p>If you want to create header, body content &amp; footer for your mobile website or application, then you should write your HTML markup as shown like below:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div data-role=&quot;header&quot;&gt;
&lt;div data-role=&quot;content&quot;&gt;
&lt;div data-role=&quot;footer&quot;&gt;
</pre>
<p>As you can seen above, &#8220;<strong>data-role</strong>&#8221; attribute has been used to inform jQuery Mobile to assign the specific role to the specified div.</p>
<h3>Button</h3>
<p>Let say, we want to create a click-able button, then we should assign &#8220;<strong>button</strong>&#8221; as a value for &#8220;data-role&#8221; attribute.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a href=&quot;#&quot; data-role=&quot;button&quot;&gt;Button&lt;/a&gt;
</pre>
<h4>Output:</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/button.jpg" alt="jQuery Mobile Button" title="jQuery Mobile Button" width="328" height="63" class="alignnone size-full wp-image-2311" /></p>
<p>The markup above will turn the link element into a button so it&#8217;s easy to click. Besides that, you can add an icon with the &#8220;data-icon&#8221; attribute and set its position with the &#8220;data-iconpos&#8221; attribute. Example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a href=&quot;#&quot; data-role=&quot;button&quot; data-icon=&quot;check&quot; data-iconpos=&quot;right&quot;&gt;Button With Icon&lt;/a&gt;
</pre>
<h4>Output</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/button_with_icon.jpg" alt="Button With Icon" title="Button With Icon" width="328" height="63" class="alignnone size-full wp-image-2312" /></p>
<p>The framework has provided ample of icons for us to use it in our projects, you can <a href="http://jquerymobile.com/test/docs/buttons/buttons-icons.html" title="jQuery Mobile Button Icons" target="_blank">click here to see the complete list of available icons for button.</a></p>
<h3>Grouped Buttons</h3>
<p>Sometimes, we may want to visually group a set of buttons together to form a single block that looks like a navigation component. With jQuery Mobile framework, we can easily get the effect by writing our code in this way:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div data-role=&quot;controlgroup&quot;&gt;
&lt;a href=&quot;index.html&quot; data-role=&quot;button&quot;&gt;Yes&lt;/a&gt;
&lt;a href=&quot;index.html&quot; data-role=&quot;button&quot;&gt;No&lt;/a&gt;
&lt;a href=&quot;index.html&quot; data-role=&quot;button&quot;&gt;Confirm Later&lt;/a&gt;
&lt;/div&gt;
</pre>
<h4>Output</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/grouped_button.jpg" alt="Grouped Buttons" title="Grouped Buttons" width="336" height="139" class="alignnone size-full wp-image-2314" /></p>
<p>Just wrap all the buttons in a div container with &#8216;<strong>data-role=&#8221;controlgroup&#8221;</strong>&#8216; attribute. The &#8220;controlgroup&#8221; will tell the framework to remove all margin and drop shadow between the buttons and grouped them all together.</p>
<p>By default, the grouped buttons presented as a vertical list, but the framework do also allow us to arrange the grouped buttons horizontally by adding the &#8216;<strong>data-type=&#8221;horizontal&#8221;</strong>&#8216;.</p>
<h4>Output</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/grouped_button_horizontal.jpg" alt="Horizontal Grouped Buttons" title="Horizontal Grouped Buttons" width="286" height="53" class="alignnone size-full wp-image-2315" /></p>
<h3>List Views</h3>
<p>A list views is an unordered list that contains click-able list of items with a &#8216;<strong>data-role=&#8221;listview&#8221;</strong>&#8216; attribute. By declaring a &lt;ul&gt; with &#8216;data-role=&#8221;listview&#8221;&#8216;, the framework will apply all necessary styles to transform the list into a mobile-friendly list view with right arrow indicator that fills the full width of the browser window. Example of a simple list view:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul data-role=&quot;listview&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;index.html&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;about.html&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;contact.html&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<h4>Output</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/list_views.jpg" alt="List Views" title="List Views" width="352" height="129" class="alignnone size-full wp-image-2316" /></p>
<p>Usually, web designers will add thumbnails or icons to the left of a list item. By adding thumbnails into the list views, the jQuery Mobile framework will scale the image to 80 pixels square.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul data-role=&quot;listview&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;index.html&quot;&gt;&lt;img src=&quot;http://www.onlywebpro.com/wp-content/uploads/2010/10/thumb_post05.jpg&quot; /&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;about.html&quot;&gt;&lt;img src=&quot;http://www.onlywebpro.com/wp-content/uploads/2010/11/thumb_post17.jpg&quot; /&gt;About&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;contact.html&quot;&gt;&lt;img src=&quot;http://www.onlywebpro.com/wp-content/uploads/2011/10/introduction-to-device-orientation-with-html5.jpg&quot;/&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<h4>Output</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/list_views_with_thumb.jpg" alt="List Views With Thumbnails" title="List Views With Thumbnails" width="351" height="252" class="alignnone size-full wp-image-2317" /></p>
<p>For the icons, if you want to add a standard size 16 x 16px of icon into the list item, then you could specify it by adding &#8220;<strong>ui-li-icon</strong>&#8221; to the image element.</p>
<h3>Dialogs</h3>
<p>We can present a page into a modal dialog by adding &#8216;<strong>data-rel=&#8221;dialog&#8221;</strong>&#8216; to the click-able link. Usually diaogs is used for confirmation of a decision, such as money transaction. Example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a href=&quot;confirm.html&quot; data-role=&quot;button&quot; data-rel=&quot;dialog&quot;&gt;Open dialog&lt;/a&gt;
</pre>
<h4>Output</h4>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/dialogs.jpg" alt="Dialogs" title="Dialogs" width="348" height="261" class="alignnone size-full wp-image-2320" /></p>
<p>By default, the dialog will open by a &#8220;pop&#8221; transition, but the framework do allow us to specify any page transition using &#8220;<strong>data-transition</strong>&#8221; attribute.</p>
<h3>Page Transitions</h3>
<p>Here is a list of page transitions that available for us to apply to any page link or form submission with Ajax navigation.</p>
<ul>
<li>fade</li>
<li>pop</li>
<li>flip</li>
<li>turn</li>
<li>flow</li>
<li>slidefade</li>
<li>slide</li>
<li>slideup</li>
<li>slidedown</li>
<li>none</li>
</ul>
<p>Example of usage, open a dialog with &#8220;flip&#8221; page transition:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a href=&quot;confirm.html&quot; data-role=&quot;button&quot; data-rel=&quot;dialog&quot; data-transition=&quot;flip&quot;&gt;Open dialog&lt;/a&gt;
</pre>
<p>You can view the set of demos on supported browser such as latest Chrome and Firefox.</p>
<p><a class="demo_btn" target="_blank" href="http://www.onlywebpro.com/demo/jquery/page_transition_demo.html">View Page Transition Demo</a></p>
<h3>Conclusion</h3>
<p>You have just learned to apply HTML5 data-* attributes to the HTML elements to transform them into fingers friendly elements. And you also learned that how the jQuery Mobile relies on the data-* attributes to support various UI elements, transitions, and page structure.</p>
<p>In the next coming tutorial, we will discuss more on the form elements that used in jQuery Mobile. Please follow us on either <a href="https://www.facebook.com/pages/Connect-with-onlyWebPro/149917668368025" title="onlyWebPro Facebook Page" target="_blank">Facebook</a>, <a href="http://twitter.com/onlyWebPro" title="onlyWebPro Twitter Page" target="_blank">Twitter</a>, <a href="https://plus.google.com/100910543735224109915/posts" title="onlyWebPro Google+ Page" target="_blank">Google+</a>, <a href="http://www.stumbleupon.com/stumbler/onlyWebPro" title="onlyWebPro Stumble Upon Page" target="_blank">Stumble Upon</a> or <a href="http://my.linkedin.com/groups?gid=3345101" title="onlyWebPro LinkedIn Group" target="_blank">LinkedIn </a>for upcoming updates!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2012/07/15/jquery-mobile-for-absolute-beginners-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery Mobile for Absolute Beginners &#8211; Part 1</title>
		<link>http://www.onlywebpro.com/2012/06/29/jquery-mobile-for-absolute-beginners-part-1/</link>
		<comments>http://www.onlywebpro.com/2012/06/29/jquery-mobile-for-absolute-beginners-part-1/#comments</comments>
		<pubDate>Fri, 29 Jun 2012 06:52:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mobile Content]]></category>

		<guid isPermaLink="false">http://www.onlywebpro.com/?p=2263</guid>
		<description><![CDATA[The jQuery Mobile is a framework that built on top of the jQuery and jQuery UI foundation. The framework allow us to develop a single mobile web applications that work across smartphones, platforms and tablets.]]></description>
				<content:encoded><![CDATA[<div class="tutorial_details">
<h3>The Full Series</h3>
<ul>
<li><a href="http://www.onlywebpro.com/2012/06/29/jquery-mobile-for-absolute-beginners-part-1/">Part 1: Introduction to jQuery Mobile &amp; Page Structure</a></li>
<li><a href="http://www.onlywebpro.com/2012/07/15/jquery-mobile-for-absolute-beginners-part-2/">Part 2: Buttons, List Views, Dialogs &amp; Transitions</a></li>
<li><a href="http://www.onlywebpro.com/2012/08/31/jquery-mobile-for-absolute-beginners-part-3/">Part 3: Form Elements</a></li>
<li><a href="http://www.onlywebpro.com/2012/09/17/jquery-mobile-for-absolute-beginners-part-4/">Part 4: Touch Events</a></li>
</ul>
</div>
<p>Over the past few years, the iPhone 3GS gains attention from the public, smart devices started to appear that allowed us to do personal email, virtual social, e-commerce and the mobile era began to grow.  We have seen a tremendous growth in browser and OS support for mobile websites, most notably is Apple iOS devices and Google Android Devices.</p>
<p>Due to multiple platforms, screen sizes, browsers, up until recently it was still very difficult to design and develop a single piece of mobile theme that able to work across all these platforms and deceives. Thanks god that, jQuery mobile  has come to solve all these problem for us.</p>
<h3>Introduction to jQuery Mobile</h3>
<p>The jQuery Mobile is a framework that built on top of the jQuery and jQuery UI foundation. The framework allow us to develop a single mobile web applications that work across smartphones, platforms and tablets. In addition, one for the great features that jQuery Mobile is &#8220;<strong>Progressive enhancement and graceful degradation</strong>&#8220;, which means that jQuery Mobile will fully leverages the latest HTML5, CSS3, and JavaScript on the supported modern devices and will still provide the best possible experience, basic functionality and basic content for less capable devices as well.</p>
<p>The framework itself is a separated from jQuery core, which you have to download it from <a title="jQuery Mobile" href="http://jquerymobile.com/" target="_blank">jQuery Mobile Official Website</a>.</p>
<h3>List of Supported Mobile Devices / OS Platforms</h3>
<p>The jQuery Mobile framework currently is supporting 3 graded devices:</p>
<h4>A Grade</h4>
<p>The framework will provide full experience with Ajax-based animated page transitions to all platforms that fall under this category. Some of the common platforms that fall under this category are:</p>
<ul>
<li>Apple iOS 3.2-5.0</li>
<li>Android 2.1-2.3</li>
<li>Android 3.1 (Honeycomb)</li>
<li>Android 4.0 (ICS)</li>
<li>Windows Phone 7-7.5</li>
<li>Blackberry 6.0, 7</li>
<li>Blackberry Playbook (1.0-2.0)</li>
<li>Firebox Mobile (10 Beta)</li>
<li>Opera Mobile 11.5</li>
<li>Kindle 3 and Fire</li>
</ul>
<h4>B Grade</h4>
<p>The devices / platforms that fall under grade B, are able to view jQuery Mobile page with enhanced experience EXCEPT without Ajax navigation features.</p>
<ul>
<li>Blackberry 5.0</li>
<li>Opera Mini (5.0-6.5)</li>
<li>Nokia Symbian^3</li>
</ul>
<h4>C Grade</h4>
<p>Lastly, grade C devices / platforms users are able to view the basic content and access basic functionality of page. The devices / platforms are:</p>
<ul>
<li>Blackberry 4.x</li>
<li>Windows Mobile</li>
<li>All older smartphone platforms and feature phones</li>
</ul>
<p>For full list of updated devices / platforms, please visit <a title="jQuery Mobile Supported Devices / Platforms" href="http://jquerymobile.com/gbs/" target="_blank">jQuery Mobile site</a> for more information.</p>
<h3>The Basic Structure of jQuery Mobile Page</h3>
<p>Ok, let&#8217;s start to build our first jQuery Mobile page. Before we start, we have to get to know the basic structure of a jQuery Mobile page. Basically, a jQuery Mobile page should consists of 3 sections, which is:</p>
<ul>
<li><strong>Header bar</strong>: Usually contains page title and back button.</li>
<li><strong>Content region</strong>: All your page content should be placed under this section.</li>
<li><strong>Footer bar</strong>: Contain footer navigation and copyright information.</li>
</ul>
<p>That&#8217;s it! Simple enough right? Let&#8217;s start to build it!</p>
<p>Open up your web authoring tools, and place the following HTML code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt; 
&lt;html&gt; 
	&lt;head&gt; 
	&lt;title&gt;jQuery Mobile Tutorial From onlyWebPro.com&lt;/title&gt; 
	&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt; 
	&lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css&quot; /&gt;
	&lt;script src=&quot;http://code.jquery.com/jquery-1.7.1.min.js&quot;&gt;&lt;/script&gt;
	&lt;script src=&quot;http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt; 
&lt;body&gt; 
&lt;div data-role=&quot;page&quot;&gt;
	&lt;div data-role=&quot;header&quot;&gt;
		&lt;h1&gt;Page Title&lt;/h1&gt;
	&lt;/div&gt;&lt;!-- /header --&gt;

	&lt;div data-role=&quot;content&quot;&gt;	
		&lt;p&gt;Hello world&lt;/p&gt;		
	&lt;/div&gt;&lt;!-- /content --&gt;
    
    &lt;div data-role=&quot;footer&quot;&gt;
		&lt;h1&gt;Footer&lt;/h1&gt;
	&lt;/div&gt;&lt;!-- /footer --&gt;
&lt;/div&gt;&lt;!-- /page --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h4>Explanation:</h4>
<ul>
<li>At the first line, we have define the document type as HTML5 using &lt;!DOCTYPE html&gt;</li>
<li>At line 05, we use the <a title="Viewport Meta Tag For Mobile Devices" href="http://www.onlywebpro.com/2011/08/30/viewport-meta-tag-for-mobile-devices/" target="_blank">viewport meta tag</a> to set the screen width to the pixel width of the device</li>
<li>At lines 06, 07 and 08, we load 3 necessary jQuery Mobile components into the document</li>
<li>At line 11 &#8211; 23, a div with a data-role of &#8220;page&#8221; is the wrapper used to delineate a page, and the header bar with data-role=&#8221;header&#8221;, content region div with data-role=&#8221;content&#8221; and footer bar with data-role=&#8221;footer&#8221; are added inside to create a basic jQuery Mobile page.</li>
</ul>
<p>Do you notice that from the page wrapper, header bar till the footer bar, every one of it has an attribute call &#8220;<strong>data- </strong>&#8220;. These data- attributes are HTML5 attributes that used throughout jQuery Mobile to transform basic markup into an enhanced and styled widget. We will cover the details on the upcoming tutorial.</p>
<p>Save your file and preview it on supported browser, you should see your document displayed exactly as the following image:</p>
<p><img src="http://www.onlywebpro.com/wp-content/uploads/2012/11/jquery_mobile_simple.jpg" alt="jQuery Mobile Page" title="jQuery Mobile Page" width="410" height="314" class="alignnone size-full wp-image-2293" /></p>
<p>Yeah! You have just created a jQuery Mobile Page, which is work across devices, platforms and screen sizes.</p>
<h3>Conclusion</h3>
<p>You have just learned about the jQuery Mobile framework and how the framework optimized and rendered your mobile page on smartphones, tablets and less capable devices. Besides, you have also learned to create a jQuery Mobile page.</p>
<p>In the next tutorial, we will discuss on how the HTML5 data-* attributes that jQuery Mobile relies on to support various UI elements, transitions, and page structure as well. Stay tunes!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onlywebpro.com/2012/06/29/jquery-mobile-for-absolute-beginners-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
