<?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>Stephen McIntyre &#187; CSS</title>
	<atom:link href="http://stephenmcintyre.net/category/blog/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://stephenmcintyre.net</link>
	<description>Young Scottish Web Designer</description>
	<lastBuildDate>Thu, 10 Jun 2010 15:25:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Untold Entertainment Made in jQuery Part 3 &#8211; The Project Slider</title>
		<link>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-project-slider/</link>
		<comments>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-project-slider/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 15:00:46 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=577</guid>
		<description><![CDATA[
Being a showcase for the Flash work of Untold Entertainment, the image slider is used as the main focus of the home page and displays his latest projects. Continuing from the first two tutorials, I&#8217;ll now show you how to create this slider with jQuery.
We&#8217;ll be treating the slider as a separate element from our [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/06/untold-slider.png"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/06/untold-slider.png" alt="" title="untold-slider" width="400" height="308" class="aligncenter size-full wp-image-584" /></a></p>
<p>Being a showcase for the Flash work of <a href="http://untoldentertainment.com">Untold Entertainment</a>, the image slider is used as the main focus of the home page and displays his latest projects. Continuing from the <a href="/blog/untold-entertainment-in-jquery-animating-twitter-text/">first</a> <a href="/blog/untold-entertainment-in-jquery-styling-the-twitter-bar/">two</a> tutorials, I&#8217;ll now show you how to create this slider with jQuery.</p>
<p>We&#8217;ll be treating the slider as a separate element from our Twitter bar before, so no need to use old code here.</p>
<p>With the abundance of jQuery image gallery plugins and scripts it&#8217;s safe to say that jQuery makes this sort of thing in particular run a lot more smoothly than with plain JavaScript. This section will be the easiest part of the series.</p>
<p>Let&#8217;s dive in.<span id="more-577"></span></p>
<p>First have a look at the <a href="/examples/untold/part-3.html">slider demo</a>.</p>
<h3>The Markup</h3>
<p>We&#8217;ll start with the HTML tags.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slider&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prev&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;next&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p><strong>#slider:</strong> The container element that wraps everything.</p>
<p><strong>#image:</strong> This contains the large image and navigation buttons (<code>#prev</code> and <code>#next</code>). The image is actually a background, but more on that later.</p>
<p><strong>#content:</strong> Holds elements for the project title (<code>&lt;h3&gt;</code>) and excerpt (<code>&lt;p&gt;</code>). The <code>&lt;a&gt;</code> inside the title creates a link to the page that the project is on.</p>
<h3>Setting Up jQuery and the Projects Array</h3>
<p>If you&#8217;ve followed the previous tutorials, including jQuery is still as straight-forward as it was before. Again, we&#8217;ll be drawing it in from the Google Code repository.</p>
<p>I&#8217;ve also added an extra empty tag that we can add our own code into.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>

<p>JavaScript should go above the main HTML content (at the start of the <code>&lt;body&gt;</code> if your document has it).</p>
<p>Inside the empty script tag, set up our &#8220;projects&#8221; array like so.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">var</span> projects <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/img/projects/bestEd/hedgeYourBets/thumb.jpg&quot;</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Best Ed – Hedge Your Bets!&quot;</span><span style="color: #339933;">,</span>
    excerpt<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
    link<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/2009/09/17/best-ed-hedge-your-bets/&quot;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/img/projects/bestEd/crossingDog/thumb.jpg&quot;</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Best Ed – Crossing Dog&quot;</span><span style="color: #339933;">,</span>
    excerpt<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
    link<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/2009/09/17/best-ed-crossing-dog/&quot;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/img/projects/bloat/bloat.jpg&quot;</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Bloat.&quot;</span><span style="color: #339933;">,</span>
    excerpt<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Our company president created Bloat. in roughly twenty-two hours at TOJam 4, a weekend-long game development expo. Bloat. is a true [...]&quot;</span><span style="color: #339933;">,</span>
    link<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/2009/05/05/bloat/&quot;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/img/projects/AWTY/eyeInTheSky/EyeInTheSky.jpg&quot;</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Eye in the Sky&quot;</span><span style="color: #339933;">,</span>
    excerpt<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;We created this spot-the-differences game for Sinking Ship Entertainment’s Are We There Yet? World Adventure kids’ travel teevee [...]&quot;</span><span style="color: #339933;">,</span>
    link<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/2008/11/28/eye-in-the-sky/&quot;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/img/projects/AWTY/trainTrack/trainTrack.jpg&quot;</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Train Track!&quot;</span><span style="color: #339933;">,</span>
    excerpt<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;We were approached by Sinking Ship Entertainment to create an eye-spy game for their kids’ travel teevee show Are We There Yet? World [...]&quot;</span><span style="color: #339933;">,</span>
    link<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.untoldentertainment.com/blog/2008/11/28/train-track/&quot;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> project_id <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The script uses JSON notation to create an array of objects, each with the same set of attributes: &#8220;image&#8221;, &#8220;title&#8221;, &#8220;excerpt&#8221; and &#8220;link&#8221;.</p>
<p>We would print these onto the page using PHP, looping through database rows in a WordPress setup. This won&#8217;t be covered as it&#8217;s irrelevant how the information gets to the page. This set of example project data will work on its own for now.</p>
<p>The <code>project_id</code> variable holds the array key for our current project data object. This means we can change this number (with the navigation buttons) and call a whole new set of data when we want it to load.</p>
<h3>Attaching Clicks to the Navigation Buttons</h3>
<p>To allow ourselves to reference our HTML elements, we have to wait for them to load before we call our JavaScript to interact with them. For this we can either place the JavaScript after our HTML, or use jQuery&#8217;s nice &#8220;document ready&#8221; check to do this for us, and still keep our JavaScript at the top.</p>
<p>Here I&#8217;ll use the jQuery method. Generally it lets us to load all of our JavaScript first, allowing a smoother page load and cuts out some jerky effects.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">  $<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#prev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      project_id<span style="color: #339933;">--;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>project_id <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        project_id <span style="color: #339933;">=</span> projects.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      load_project<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#next'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      project_id<span style="color: #339933;">++;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>project_id <span style="color: #339933;">&gt;</span> projects.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        project_id <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      load_project<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    load_project<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In each case, clicking one of the buttons adds or removes one from <code>project_id</code>. If it is less than zero or greater than our maximum index in <code>projects</code> (five) then it is reset to the other side of the scale.</p>
<p>For example, pressing the previous button when you are looking at the first project (ID of zero), the slider skips to the fifth project in the list. Clicking next from here takes you back to the first element, and so on.</p>
<h3>load_project()</h3>
<p>This is what is called when the page is loaded and when a navigation button is clicked. It takes the <code>project_id</code> and populates the slider with all information attached to that array key inside <code>projects</code>.</p>
<p>I&#8217;ll go through this one a bit at a time.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">function</span> load_project<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> project_data <span style="color: #339933;">=</span> projects<span style="color: #009900;">&#91;</span>project_id<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#image'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'backgroundImage'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#content h3 a'</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span> project_data.<span style="color: #660066;">link</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>project_data.<span style="color: #660066;">title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#content p'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>project_data.<span style="color: #660066;">excerpt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>project_data.<span style="color: #660066;">excerpt</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#content p'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' &lt;a href=&quot;'</span> <span style="color: #339933;">+</span> project_data.<span style="color: #660066;">link</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;keep reading&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;img src=&quot;'</span> <span style="color: #339933;">+</span> project_data.<span style="color: #660066;">image</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; /&gt;'</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>responseText<span style="color: #339933;">,</span> textStatus<span style="color: #339933;">,</span> XMLHttpRequest<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#image'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'backgroundImage'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'url(&quot;'</span> <span style="color: #339933;">+</span> project_data.<span style="color: #660066;">image</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Line 5:</strong> Removes any overridden background image styles on &#8220;#image&#8221; to display the &#8220;loading&#8221; spinner.</p>
<p><strong>Lines 7-9:</strong> Adds an <code>href</code> to the title allowing it to link to an external page, and fills in the title text. These are both taken from the current item in the list of projects (referenced here as <code>project_data</code>).</p>
<p><strong>Lines 11-16:</strong> The first line fills in the <code>&lt;p&gt;</code> tag with the excerpt text. If the excerpt is not an empty string, an extra &#8220;keep reading&#8221; link is also added to the end of the text linking to the project page. This is the same link used for the title.</p>
<p><strong>Lines 18 and 19:</strong> jQuery creates a DOM element of an image, with its source linking to the current project&#8217;s image URL. We can then use this to track how long it takes to load, as done here with the built-in <code>.load()</code> method.</p>
<p>When the element has loaded (read: the image has been fully downloaded into your browser), it issues a callback to JavaScript. Anything we put inside of this callback will only be run once the requested image is available to be displayed. The main reason here being to switch out the &#8220;loading&#8221; spinner.</p>
<p><strong>Line 21:</strong> Here we edit the background of the &#8220;#image&#8221; container again, this time changing it to the image for the current project and overriding the spinner.</p>
<h3>Adding Style</h3>
<p>If you&#8217;re familiar with basic CSS, these will be pretty straight-forward.</p>
<p>However, pay particular attention to the <code>:hover</code> pseudo on the navigation buttons. Since we want the buttons to animate when we hover over them and not on its own or on a timer, it&#8217;s useful to do this with CSS here instead of JavaScript.</p>
<p>Again, this part goes right at the top before everything else (in the <code>&lt;head&gt;</code> section if your document has one).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
  <span style="color: #00AA00;">*</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #cc00cc;">#slider</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">466px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Verdana</span><span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> Arial<span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #cc00cc;">#image</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'loader.gif'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">340px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #cc00cc;">#content</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #cc00cc;">#image</span> a
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">280px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #3333ff;">:<span style="color: #993333;">none</span> </span>url<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'prev.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#222</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  a<span style="color: #cc00cc;">#prev</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'prev.gif'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  a<span style="color: #cc00cc;">#prev</span><span style="color: #3333ff;"><span style="color: #00AA00;">:</span>hover
  </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'prev-hover.gif'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  a<span style="color: #cc00cc;">#next</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'next.gif'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  a<span style="color: #cc00cc;">#next</span><span style="color: #3333ff;"><span style="color: #00AA00;">:</span>hover
  </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'next-hover.gif'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>And that&#8217;s it. Here is what your final slider will look like.</p>
<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/06/untold-js-slider.png"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/06/untold-js-slider.png" alt="" title="untold-js-slider" width="400" height="381" class="aligncenter size-full wp-image-590" /></a></p>
<p>Now comes the fun part. Next week I&#8217;ll be showing you how to make that roll-out tongue on the menu bar, all without a bit of Flash.</p>
<p>Connect with my blog&#8217;s <a href="http://feeds.feedburner.com/stephenmcintyre?format=html">news stream</a> to get notified as soon as it&#8217;s up.</p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-project-slider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Untold Entertainment Made in jQuery Part 2 – Styling the Twitter Bar</title>
		<link>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-styling-the-twitter-bar/</link>
		<comments>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-styling-the-twitter-bar/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 00:50:17 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=556</guid>
		<description><![CDATA[Carrying on from the first part of creating a Flash-less home page on Untold Entertainment, we add to the tutorial on animating Twitter text with some more usability and style.
We start off by generating links (to URLs and Twitter pages) inside the text, make a couple of buttons to skip the tweets backwards and forwards, [...]]]></description>
			<content:encoded><![CDATA[<p>Carrying on from the first part of creating a Flash-less home page on <a href="http://untoldentertainment.com">Untold Entertainment</a>, we add to the tutorial on <a href="/blog/untold-entertainment-in-jquery-animating-twitter-text/">animating Twitter text</a> with some more usability and style.</p>
<p>We start off by generating links (to URLs and Twitter pages) inside the text, make a couple of buttons to skip the tweets backwards and forwards, then animate the Twitter bird and speech bubble as a background.<span id="more-556"></span></p>
<p>Try out the new <a href="/examples/untold/part-2.html">styled Twitter bar demo</a>.</p>
<h3>The New HTML Structure</h3>
<p>To add in our new elements, we&#8217;ll have to mess about with the layout of our HTML tags.</p>
<p>The container still holds the text as before, but we add in the bird image and navigation buttons inside a div. The holder is there to keep the buttons beside the text, and the outer wrapper collects all of it including the bird image.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrapper&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;holder&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tweet_buttons&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prev&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;#9668;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;next&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;#9658;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bird&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bird.gif&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bird&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>The HTML entities are the forward and backward pointing arrowheads you see. These can be images, but the entities will do for now to make things simpler.</p>
<h3>Adding Links to the Text</h3>
<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/06/bird-static.png"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/06/bird-static.png" alt="" title="bird-static" width="400" height="39" class="aligncenter size-full wp-image-570" /></a></p>
<p>To find URLs and Twitter usernames, we have to do a check on each word. Here we&#8217;re looking for anything starting with &#8220;http://&#8221; and &#8220;@&#8221; respectively.</p>
<p>We change our <code>add_text()</code> method from last time with the following lines of code. This should replace the line beginning with <code>var new_text = ...</code>.</p>
<p>The first three sections change text inside <code>add_text()</code>. For the full replacement code, use the new function at the end of the tutorial.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> word <span style="color: #339933;">=</span> updates<span style="color: #009900;">&#91;</span>update_key<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>word_key<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>word.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'@'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  word <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a href=&quot;http://twitter.com/'</span> <span style="color: #339933;">+</span> word.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> word <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>word.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'http://'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  word <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a href=&quot;'</span> <span style="color: #339933;">+</span> word <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> word <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> new_text <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' &lt;span class=&quot;rot'</span> <span style="color: #339933;">+</span> rand <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> word <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/span&gt;'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This wraps any usernames and URLs inside an anchor <code>&lt;a&gt;</code> tag and turns them into clickable links.</p>
<h3>Animating the bird</h3>
<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/06/bird-chirp.png"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/06/bird-chirp.png" alt="" title="bird-chirp" width="400" height="38" class="aligncenter size-full wp-image-569" /></a></p>
<p>These few lines go after <code>$('#container').html(new_text);</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bird'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'bird_shout.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bird'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">oneTime</span><span style="color: #009900;">&#40;</span>chirp_time<span style="color: #339933;">,</span> <span style="color: #3366CC;">'blabel_'</span> <span style="color: #339933;">+</span> update_key<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bird'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'bird.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The variable <code>chirp_time</code> should be added to our list of Variables at the top of the JavaScript section. Here I&#8217;ve set it to 100 as it works well for the GIF animation. And while you&#8217;re there add in a delay that we&#8217;ll use later.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #003366; font-weight: bold;">var</span> length_min <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> length_max <span style="color: #339933;">=</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> chirp_time <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> delay <span style="color: #339933;">=</span> <span style="color: #CC0000;">2000</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is what makes the bird&#8217;s mouth move, held open by the time we&#8217;ve specified in <code>chirp_time</code> as 100 milliseconds.</p>
<h3>Animating the Speech Bubble</h3>
<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/06/bird-transition.png"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/06/bird-transition.png" alt="" title="bird-transition" width="400" height="37" class="aligncenter size-full wp-image-571" /></a></p>
<p>Look for the &#8220;if&#8221; statement of <code>if(word_key < updates...</code>, add this line just inside.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bubble'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-image'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'url(&quot;bubble.gif&quot;)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This sets the background to be the non-animated image of a speech bubble.</p>
<p>In the "else" of this statement, look for the first timer event (the first line inside). In here we add the code to make the background animate as the text transitions into a new tweet. It's similar to the line above, but instead links to an animated image.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bubble'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-image'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'url(&quot;bubble_animated.gif&quot;)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Setting Up the Controls</h3>
<p>To add JavaScript "onclick" events to our navigational buttons, we call jQuery on page load. This is to allow the elements to be created before we bind events to them.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#prev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">stopTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    word_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    update_key<span style="color: #339933;">--;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>update_key <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      update_key <span style="color: #339933;">=</span> updates.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bubble'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-image'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'url(&quot;bubble_animated.gif&quot;)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">oneTime</span><span style="color: #009900;">&#40;</span>delay<span style="color: #339933;">,</span> <span style="color: #3366CC;">'label_'</span> <span style="color: #339933;">+</span> word_key<span style="color: #339933;">,</span> add_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#next'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">stopTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    word_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    update_key<span style="color: #339933;">++;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>update_key <span style="color: #339933;">&gt;</span> updates.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      update_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bubble'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-image'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'url(&quot;bubble_animated.gif&quot;)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">oneTime</span><span style="color: #009900;">&#40;</span>delay<span style="color: #339933;">,</span> <span style="color: #3366CC;">'label_'</span> <span style="color: #339933;">+</span> word_key<span style="color: #339933;">,</span> add_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The code should look very familiar to what's inside <code>add_text()</code>. Simply put, the <code>#previous</code> code skips to the previous tweet and <code>#next</code> goes to the one after, so this changes the increment or decrement of the <code>update_key</code> variable.</p>
<h3>Updating the Stylesheet</h3>
<p>The new styles for these elements are also as follows.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#bubble</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">700px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #3333ff;">:inline-</span>block<span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'bubble.gif'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span> <span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#buttons</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
  <span style="color: #cc00cc;">#buttons</span> a
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#bird</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>And that's it for now.</p>
<p>Next we'll make the image slider.</p>
<p>(Here's the new code for <code>add_text()</code>)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> add_text<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> rand <span style="color: #339933;">=</span> Math.<span style="color: #660066;">ceil</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> word <span style="color: #339933;">=</span> updates<span style="color: #009900;">&#91;</span>update_key<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>word_key<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>word.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'@'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    word <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a href=&quot;http://twitter.com/'</span> <span style="color: #339933;">+</span> word.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> word <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>word.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'http://'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    word <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a href=&quot;'</span> <span style="color: #339933;">+</span> word <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> word <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> new_text <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' &lt;span class=&quot;rot'</span> <span style="color: #339933;">+</span> rand <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> word <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/span&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>new_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bird'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'bird_shout.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bird'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">oneTime</span><span style="color: #009900;">&#40;</span>chirp_time<span style="color: #339933;">,</span> <span style="color: #3366CC;">'blabel_'</span> <span style="color: #339933;">+</span> update_key<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bird'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'bird.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  word_key<span style="color: #339933;">++;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>word_key <span style="color: #339933;">&lt;</span> updates<span style="color: #009900;">&#91;</span>update_key<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bubble'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-image'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'url(&quot;bubble.jpg&quot;)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    set_timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span>
  <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">oneTime</span><span style="color: #009900;">&#40;</span>wait<span style="color: #339933;">,</span> <span style="color: #3366CC;">'reset'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      word_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
      update_key<span style="color: #339933;">++;</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>update_key <span style="color: #339933;">&gt;</span> updates.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        update_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#bubble'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-image'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'url(&quot;bubble_animated.gif&quot;)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">oneTime</span><span style="color: #009900;">&#40;</span>delay<span style="color: #339933;">,</span> <span style="color: #3366CC;">'label_'</span> <span style="color: #339933;">+</span> word_key<span style="color: #339933;">,</span> add_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-styling-the-twitter-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Untold Entertainment Made in jQuery Part 1 &#8211; Animating Twitter Text</title>
		<link>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-animating-twitter-text/</link>
		<comments>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-animating-twitter-text/#comments</comments>
		<pubDate>Thu, 27 May 2010 23:14:55 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=531</guid>
		<description><![CDATA[
Ryan Creighton&#8217;s Flash development site Untold Entertainment has a quirky home page with plenty of animation and things to click on (complete with roll-out tongue) and of course is built in Flash. Thing is, I&#8217;m against any kind of Flash interface. It&#8217;s great for games, but otherwise it&#8217;s unnecessary (which includes videos).
With the whole Adobe [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/05/untold.png"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/05/untold.png" alt="" title="untold" width="400" height="244" class="aligncenter size-full wp-image-552" /></a></p>
<p>Ryan Creighton&#8217;s Flash development site <a href="http://untoldentertainment.com">Untold Entertainment</a> has a quirky home page with plenty of animation and things to click on (complete with roll-out tongue) and of course is built in Flash. Thing is, I&#8217;m against any kind of Flash interface. It&#8217;s great for games, but otherwise it&#8217;s unnecessary (which includes videos).</p>
<p>With the whole Adobe v Apple debate that&#8217;s going on right now (yes, I said I wouldn&#8217;t mention it but it applies here &#8216;kay), it&#8217;s safe to say you&#8217;d be better placing your chips on the JavaScript and HTML5 end of the table.</p>
<p>The discouraging part is that his website could be done without Flash as most of the scrolling and animating could be done with straight JavaScript, and jQuery will help see things along smoothly.</p>
<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/05/untold-twbar.png"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/05/untold-twbar.png" alt="" title="untold-twbar" width="400" height="38" class="aligncenter size-full wp-image-553" /></a></p>
<p>Today I&#8217;ll show you how to animate the text at the top, feeding in from <a href="http://twitter.com/untoldent">his Twitter feed</a>, complete with jerky timings, slanted text and collecting feed data.<span id="more-531"></span></p>
<p>Check out the <a href="/examples/untold/part-1.html">Untold Twitter bar</a> demo.</p>
<h3>Including jQuery, Timer plugin, and Google AJAX Feed API</h3>
<p>We&#8217;ll start off by including our libraries and plugins. Here I use jQuery, the jQuery Timers plugin, and the Google AJAX Feed API &#8211; all sourced from their Google Code hosts.</p>
<p>Admittedly we won&#8217;t be using much jQuery here as the code changed quite a bit as it got added to, but it might come in handy in later tutorials. If you know how to change the scripts into plain JavaScript, by all means change those parts over.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stikked.googlecode.com/svn/trunk/static/js/jquery.timers.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.google.com/jsapi?key=YOURAPIKEY&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>

<p>More information on the API key can be found in my earlier post on <a href="/blog/guide-to-google-ajax-feed-api/">Google AJAX Feeds</a>.</p>
<p>This code goes inside the <code>&lt;body&gt;</code> element, right at the top so it loads first. There&#8217;s an extra element in there &#8211; this is where we&#8217;ll add our own JavaScript.</p>
<h3>Settings and Variables</h3>
<p>To allow us to fine tune the feel of the page later, we&#8217;ll set up a list of variables. This bit of code is the first to go inside the empty <code>&lt;script&gt;</code> tag above.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Variables - tweak as you like */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> username <span style="color: #339933;">=</span> <span style="color: #3366CC;">'UntoldEnt'</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> feed_url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://twitter.com/statuses/user_timeline/21834006.rss'</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> entry_fetches <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> interval <span style="color: #339933;">=</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> wait <span style="color: #339933;">=</span> <span style="color: #CC0000;">6000</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> length_min <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> length_max <span style="color: #339933;">=</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>These should be reasonable to understand, and what isn&#8217;t obvious will be covered later as the script develops.</p>
<h3>Collecting Feed Data</h3>
<p>In this example we want to collect the data from Twitter, or more specifically <a href="http://twitter.com/untoldent">@untoldent</a>&#8217;s account. More information on the use of the <code>google</code> object can be found on the same link as above (the <a href="/blog/guide-to-google-ajax-feed-api/">Google Feed</a> one).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Google Feed API stuff */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> updates <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> Initialize<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> feed <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">feeds</span>.<span style="color: #660066;">Feed</span><span style="color: #009900;">&#40;</span>feed_url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  feed.<span style="color: #660066;">setNumEntries</span><span style="color: #009900;">&#40;</span>entry_fetches<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  feed.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>result.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> result.<span style="color: #660066;">feed</span>.<span style="color: #660066;">entries</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> entry <span style="color: #339933;">=</span> result.<span style="color: #660066;">feed</span>.<span style="color: #660066;">entries</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">title</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>username.<span style="color: #660066;">length</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>entry.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'@'</span> <span style="color: #339933;">&amp;&amp;</span> entry.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'RT'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
          updates.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>entry.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    set_timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
google.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;feeds&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
google.<span style="color: #660066;">setOnLoadCallback</span><span style="color: #009900;">&#40;</span>Initialize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We start off by collecting the RSS feed from the <code>feed_url</code> and check there are no errors like I did before.</p>
<p>The script then loops through each feed element once it has been loaded in and removes replies and retweets. What&#8217;s left is added to our array of <code>updates</code>, split word by word into another array inside of it.</p>
<p>When this is done, <code>set_timer()</code> is called to start the actual stuff that makes it look like Untold&#8217;s Twitter bar.</p>
<h3>Creating Animated Text</h3>
<p>Last bit of JavaScript &#8211; the fancy part.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Animated Tweet stuff */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> clamp<span style="color: #009900;">&#40;</span>val<span style="color: #339933;">,</span> min<span style="color: #339933;">,</span> max<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>min<span style="color: #339933;">,</span> Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span>max<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> word_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> update_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> set_timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> clamp<span style="color: #009900;">&#40;</span>updates<span style="color: #009900;">&#91;</span>update_key<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>word_key<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">,</span> length_min<span style="color: #339933;">,</span> length_max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> timing <span style="color: #339933;">=</span> length <span style="color: #339933;">*</span> interval<span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">oneTime</span><span style="color: #009900;">&#40;</span>timing<span style="color: #339933;">,</span> <span style="color: #3366CC;">'label_'</span> <span style="color: #339933;">+</span> word_key<span style="color: #339933;">,</span> add_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> add_text<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> rand <span style="color: #339933;">=</span> Math.<span style="color: #660066;">ceil</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> new_text <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' &lt;span class=&quot;rot'</span> <span style="color: #339933;">+</span> rand <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> updates<span style="color: #009900;">&#91;</span>update_key<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>word_key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/span&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>new_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  word_key<span style="color: #339933;">++;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>word_key <span style="color: #339933;">&lt;</span> updates<span style="color: #009900;">&#91;</span>update_key<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    set_timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span>
  <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">oneTime</span><span style="color: #009900;">&#40;</span>wait<span style="color: #339933;">,</span> <span style="color: #3366CC;">'reset'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      word_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
      update_key<span style="color: #339933;">++;</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>update_key <span style="color: #339933;">&gt;</span> updates.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        update_key <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      set_timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><b>clamp:</b> In other languages, <code>clamp</code> is usually available inside a <code>Math</code> library, but not this one. So I&#8217;ve added this to make the code cleaner later.</p>
<p><b>word_key and update_key:</b> These are indexes for the <code>updates</code> array and the words inside each element. These increment by one as they are used, and then reset to zero when moving to a new element. They&#8217;re kept outside the functions so that they can be called from wherever.</p>
<p><b>set_timer:</b> First calculates a timing based on the length of the word. To avoid certain words appearing too quickly or slowly, the <code>length_min</code> and <code>length_max</code> are used from earlier to add a constrained limit on either side. It is then multiplied by <code>interval</code> &#8211; also set earlier &#8211; to work out our timer.</p>
<p>The Timers plugin is then used to add a timer to the container element. This will call <code>add_text()</code> after the set time from our previous word length is up.</p>
<p><b>add_text:</b> Starts by setting a random number. This sets our rotation later, based on four classes in a stylesheet. Each word is contained within a <code>&lt;span&gt;</code> element to treat each rotation separately.</p>
<p>The <code>.html()</code> method inside jQuery allows us to add HTML markup inside of our container. Here we add our new element (the <code>&lt;span&gt;</code> with a new word) onto the existing DOM.</p>
<p>When the word has been added, the index increases by one to access the next word. A timer is then set to add this word to the queue, which then adds it on the same way as before.</p>
<p>If there are no words left (i.e., the tweet has ended), the script stops for a period defined by <code>wait</code> and some variables are reset to prepare for a new word. This includes <code>word_key</code>, <code>update_key</code> (if needed), and resets the HTML inside the container back to being empty.</p>
<p>Again, the timer is reset to prepare for new words to be added in, once the script has come out of its pause.</p>
<h3>Rotation Styles</h3>
<p>To keep with the quirky feel of Untold&#8217;s header, the text in the tweet bar also tilts word-by-word. As we have already set up our span elements with rotation classes, all that&#8217;s left is to style them.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
<span style="color: #cc00cc;">#container</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.4em</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Verdana</span><span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> Arial<span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.rot1</span>
<span style="color: #00AA00;">&#123;</span>
  -webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>1deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  -moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>1deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  rotation<span style="color: #00AA00;">:</span> 1deg<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.rot2</span>
<span style="color: #00AA00;">&#123;</span>
  -webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  -moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  rotation<span style="color: #00AA00;">:</span> 2deg<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.rot3</span>
<span style="color: #00AA00;">&#123;</span>
  -webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-1deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  -moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-1deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  rotation<span style="color: #00AA00;">:</span> -1deg<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.rot4</span>
<span style="color: #00AA00;">&#123;</span>
  -webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  -moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  rotation<span style="color: #00AA00;">:</span> -2deg<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>As you can see, these styles use WebKit and Mozilla transforms so they&#8217;re not native to all browsers. The <code>rotation</code> attribute is also only available as part of CSS3, so again not all browsers will be using this.</p>
<p>The latest version of Firefox runs it fine, although I found problems with the latest Chrome and Safari strangley, even though they use WebKit. Basically, if the text doesn&#8217;t look slanted your browser doesn&#8217;t support rotation <img src='http://stephenmcintyre.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/05/untold-js-twbar.png"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/05/untold-js-twbar.png" alt="" title="untold-js-twbar" width="400" height="19" class="aligncenter size-full wp-image-554" /></a></p>
<p>And that&#8217;s it. I&#8217;ll be seeing how far I can go with these scripts into a pure Flash-less home page.</p>
<p>Next I&#8217;ll be adding to this Twitter bar a bit more and taking it from there.</p>
<p>I&#8217;d like to know what you think of this project. Should JavaScript be used as a preference over Flash for interface design? Are there parts of Ryan&#8217;s home page that can&#8217;t possibly be made in this way?</p>
<p>Let me know in the comments, or rant at me on <a href="http://twitter.com/_bigSteve">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/untold-entertainment-in-jquery-animating-twitter-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Messing with Background-Attachment</title>
		<link>http://stephenmcintyre.net/blog/messing-with-background-attachment/</link>
		<comments>http://stephenmcintyre.net/blog/messing-with-background-attachment/#comments</comments>
		<pubDate>Thu, 13 May 2010 21:17:00 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=489</guid>
		<description><![CDATA[
Earlier this week I came across an interesting Tumblr theme by Jarred Bishop. The site played with the background-attachment CSS property to show a unique background for each Tumblr post on his main page (depending on which post image he used) and stays static as you scroll.
I started to play around with some code to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/05/parrots.jpg"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/05/parrots.jpg" alt="" title="parrots" width="400" height="164" class="aligncenter size-full wp-image-500" /></a></p>
<p>Earlier this week I <a href="http://twitter.com/_bigSteve/status/13877279858">came across</a> an interesting Tumblr theme by <a href="http://jarredbishop.tumblr.com/">Jarred Bishop</a>. The site played with the <code>background-attachment</code> CSS property to show a unique background for each Tumblr post on his main page (depending on which post image he used) and stays static as you scroll.</p>
<p>I started to play around with some code to replicate this effect and instead came up with some different examples, while still manipulating <code>background-attachment</code>. Hit the jump for some demos.<span id="more-489"></span></p>
<p>Before we start coding, <a href="/examples/bg-attach/">check these out</a>!</p>
<p>Like them?</p>
<p>Moving the scroll bar on each box changes the effect in which the background moves inside it. You either get a simple scroller (nothing special), two garage-door-style shutters, or a really nice smooth-in animation that desaturates our parrot.</p>
<p>It&#8217;s all down to changing the <code>background-attachment</code> from &#8220;scroll&#8221; to &#8220;fixed&#8221;.</p>
<h3>Styling the Containers</h3>
<p>Here&#8217;s an example. This is from the last box in the set &#8211; the one that looks like it changes into black and white as you scroll. First we&#8217;ll set up the styles. These do most of the work.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;style<span style="color: #00AA00;">&gt;</span>
  <span style="color: #00AA00;">*</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #6666ff;">.container</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.container</span> div
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #6666ff;">.container</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
    overflow-x<span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> 
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #6666ff;">.container</span> div
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #3333ff;">:no-</span>repeat<span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'parrot.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #6666ff;">.container</span> div<span style="color: #6666ff;">.grey</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'parrot-grey.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #6666ff;">.container</span> div<span style="color: #6666ff;">.fixed</span>
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-attachment</span><span style="color: #00AA00;">:</span><span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>The first part sets all margins to zero (if you have a <code>&lt;body&gt;</code> tag it&#8217;s better to use that instead of the <code>*</code> &#8220;all&#8221; pseudo). This means we don&#8217;t get weird spacing issues with the background being in the top-left corner.</p>
<p>We set each container and the <code>&lt;div&gt;</code>s inside of them to have the same height and width, both matching your images. Means they won&#8217;t overlap each other with weird sizes.</p>
<p>The container class code gives the right side a scroll bar and removes it from the bottom (we don&#8217;t need the bottom one).</p>
<p>The rest should be okay.</p>
<h3>Adding the Containers</h3>
<p>There&#8217;s a tiny bit of HTML to add in.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fixed&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;grey fixed&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>That&#8217;s all it takes, your CSS will do the rest.</p>
<p>We give our outer div the &#8220;container&#8221; class that we set earlier. The inside elements then can be given a &#8220;fixed&#8221; class to set its background-attachment.</p>
<p>Make sure to give the second one a &#8220;grey&#8221; class to change its image if you want to. For this you definitely do, but for the shutter-style examples it depends how you want it to look.</p>
<p>So now if you want to play around with the different effects, all you have to do is add or remove the &#8220;fixed&#8221; class from the HTML above.</p>
<p>Be sure to check the source of the example page to see how I did it. Just bear in mind that there are some styles in there that are purely to demonstrate them inside the grid.</p>
<p>Things like the &#8220;bottom&#8221; and &#8220;right&#8221; classes and the &#8220;position&#8221; attribute in the container class were only created for the example, but feel free to play with them and see what you get.</p>
<p>Tracing back to the start of this post, I&#8217;ll definitely be putting something else up based on Jarred&#8217;s theme, this being the first bit of insight into how it all works.</p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/messing-with-background-attachment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Display a User&#8217;s Visited Web Pages</title>
		<link>http://stephenmcintyre.net/blog/display-users-visited-pages/</link>
		<comments>http://stephenmcintyre.net/blog/display-users-visited-pages/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 17:21:19 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=391</guid>
		<description><![CDATA[Allowing a developer to access a visitor&#8217;s browsing history is a huge security risk, that&#8217;s why it&#8217;s not possible. If you own a website that runs PHP with MySQL and handles sessions then this could be done by tracking IP addresses, user agents and so on to associate a browsing pattern with a particular person. [...]]]></description>
			<content:encoded><![CDATA[<p>Allowing a developer to access a visitor&#8217;s browsing history is a huge security risk, that&#8217;s why it&#8217;s not possible. If you own a website that runs PHP with MySQL and handles <a href="/blog/custom-php-session-class/">sessions</a> then this could be done by tracking IP addresses, user agents and so on to associate a browsing pattern with a particular person. This however can be pretty inaccurate, plus it&#8217;s only limited to your own website.</p>
<p>So what are we going to use? Well when you think about it, a user&#8217;s browsing history is stored on their computer, client-side. And what else runs client-side that us web developers can make? JavaScript and CSS. These are what we&#8217;re going to use.<span id="more-391"></span></p>
<p>Firstly, head on over to the <a href="/examples/visited/">visited demo page</a> to view what you&#8217;ll be making.</p>
<h3>The Page Links</h3>
<p>To start off we&#8217;ll set up our list of links:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;btn-all&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>All<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;btn-visited&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Visited<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;btn-unvisited&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Unvisited<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;links&quot;</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/&quot;</span>&gt;</span>http://stephenmcintyre.net/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/fragment-anchor-php/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/fragment-anchor-php/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/kongregate-badge-feed-php/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/kongregate-badge-feed-php/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/opening-new-windows-with-standards-ompliance/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/opening-new-windows-with-standards-ompliance/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/guide-to-google-ajax-feed-api/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/guide-to-google-ajax-feed-api/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/custom-php-session-class/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/custom-php-session-class/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/let-your-database-do-it/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/let-your-database-do-it/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/fetch-content-using-php/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/fetch-content-using-php/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/addthis-api-social-bookmarks/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/addthis-api-social-bookmarks/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://stephenmcintyre.net/blog/jquery-parallax-scrolling/&quot;</span>&gt;</span>http://stephenmcintyre.net/blog/jquery-parallax-scrolling/<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Here we have a list of article links from this website, and above them are some links to control which of the elements we will be showing. </p>
<p>Note the <code>&lt;br/&gt;</code> inside the <code>&lt;a&gt;</code> tags. These make them display properly when some elements are removed. I was going to use an unordered list, but this looked much nicer.</p>
<h3>Controlling the Page with JavaScript</h3>
<p>Now, to let those top links control our list, we&#8217;ll give them some JavaScript.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#btn-all'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#links'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'visited'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'unvisited'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#btn-visited'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#links'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'unvisited'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'visited'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#btn-unvisited'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#links'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'visited'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'unvisited'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>The top line fetches jQuery from the Google code repository.</p>
<p>Each nested part of the jQuery code in the next <code>&lt;script&gt;</code> tag sets a &#8220;click&#8221; event for each top link, and removes or adds CSS classes to show each element properly.</p>
<p>Note that the classes only tell the browser which mode we are currently in and do not check whether the pages have actually been visited. With some clever CSS, we can properly display the links for this purpose.</p>
<p>This JavaScript snippet can go anywhere on the page, since this bit of jQuery will only run once the rest of the content has loaded.</p>
<h3>Visited and Unvisited Links in CSS</h3>
<p>This is the key in separating out our links. Remember to put this code at the top of your page (in the <code>&lt;head&gt;</code> if it has one).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
a<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#btn-all</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#btn-unvisited</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#links</span> a<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#06f</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#btn-visited</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#links</span> a<span style="color: #3333ff;">:visited</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#d5d</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#links</span><span style="color: #6666ff;">.unvisited</span> a<span style="color: #3333ff;">:visited</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#links</span><span style="color: #6666ff;">.visited</span> a<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#links</span><span style="color: #6666ff;">.visited</span> a<span style="color: #3333ff;">:visited</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#links</span><span style="color: #6666ff;">.unvisited</span> a<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>The useful part here is the <code>:visited</code> pseudo selector, which tells your browser to take any elements linking to a page from your history and display them differently.</p>
<p>Take lines 17-19 for example. Clicking &#8220;Unvisited&#8221; will set the <code>links</code> div element to have an <code>unvisited</code> class. Thanks to the <code>:visited</code> selector and setting the style to <code>display:none</code>, this means that any links that you have visited will not be shown. This is what we want.</p>
<p>Also, if &#8220;Visited&#8221; has been clicked, all links will be hidden. The style below these lines then resets all visited links so that only those are shown.</p>
<p>Don&#8217;t worry if it seems a bit confusing, just paste the source from the <a href="/examples/visited/">visited demo page</a> into an HTML editor and have a play around with it, see where it takes you.</p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/display-users-visited-pages/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using jQuery To Create Parallax Scrolling Backgrounds</title>
		<link>http://stephenmcintyre.net/blog/jquery-parallax-scrolling/</link>
		<comments>http://stephenmcintyre.net/blog/jquery-parallax-scrolling/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 22:43:00 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=309</guid>
		<description><![CDATA[Just a quick demonstration today on using JavaScript and CSS techniques to create scrolling backgrounds. Here we layer backgrounds on top of each other and change their horizontal position to move them past the viewing area. It also uses different multipliers to move the closer objects quicker, and create a parallax effect.


After you&#8217;ve checked out [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick demonstration today on using JavaScript and CSS techniques to create scrolling backgrounds. Here we layer backgrounds on top of each other and change their horizontal position to move them past the viewing area. It also uses different multipliers to move the closer objects quicker, and create a <strong>parallax</strong> effect.</p>
<p><a href="http://stephenmcintyre.net/wp-content/uploads/2010/02/parallax.jpg"><img src="http://stephenmcintyre.net/wp-content/uploads/2010/02/parallax-300x108.jpg" alt="" title="parallax" width="300" height="108" class="aligncenter size-medium wp-image-321" /></a></p>
<p><span id="more-309"></span></p>
<p>After you&#8217;ve checked out the <a href="/examples/parallax/">parallax scrolling demo</a> you can head back here to see how it&#8217;s written up.</p>
<p>I used jQuery for rapid prototyping, but naturally you can use regular JavaScript if you know the tricks to do so.</p>
<h3>The Styles</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#landscape</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#grass</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#verge</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#window</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">460px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">332px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #3333ff;">:repeat-</span>x<span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#landscape</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'landscape.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#grass</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'grass.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#verge</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'verge.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#window</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'window.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>The first section sets height, width, background position and background repeat of the <code>&lt;div&gt;</code> elements that hold our backgrounds.</p>
<p>The other ID-specific sections set the background image you want to use for each part.</p>
<p>All CSS can be tweaked to suit your own project or how you see fit.</p>
<h3>The Structure</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;landscape&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;grass&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;verge&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;window&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>All just divs inside divs here. Now, the interesting part.</p>
<h3>The Scripts</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;jquery.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> xAdd <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> scrollInterval <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		xAdd<span style="color: #339933;">++;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xAdd <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">920</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			xAdd <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#landscape'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-position'</span><span style="color: #339933;">,</span>xAdd <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px 100%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#grass'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-position'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span>xAdd <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px 100%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#verge'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-position'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span>xAdd <span style="color: #339933;">*</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px 100%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>First line imports our jQuery file and does the usual running of it in the next script tag.</p>
<p>We then set <code>xAdd = 0</code> &#8211; this will act as a <strong>counter</strong> to add to each background&#8217;s <strong>x-position</strong> and move the backgrounds horizontally behind the window.</p>
<p>Use the <code>scrollInterval</code> variable and <code>setInterval</code> method to set a function that calls every 10ms here. It&#8217;s a type of <strong>timer</strong> that will increment our <code>xAdd</code> every time it is called (10ms).</p>
<p>The if statement is a sort of <strong>garbage collector</strong>, resetting our number to 0 if it&#8217;s more than or equal to 920 (the maximum width of our images). It won&#8217;t break if you remove it, but it stops the number becoming unnecessarily high. Always good to keep these things in mind while you code.</p>
<p>The following three lines with the $ signs at the beginning allow jQuery to <strong>select</strong> our three div elements with the backgrounds in them. It then uses the <code>.css()</code> method to change their background position and creates the scrolling effect you see, since this is called every time the interval is run. There are also some multipliers on the xAdd variable in each one as mentioned earlier to speed up the <strong>closest</strong> objects.</p>
<p>So yeah, have fun with it. Just a little idea I had. Perhaps you can make better use of it than a simulation of a train journey daydream.</p>
<p>I dunno, surprise me. Let&#8217;s see what can be made of parallax scrolling in web pages. Interested to try this in a page header&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/jquery-parallax-scrolling/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Image beside link</title>
		<link>http://stephenmcintyre.net/blog/image-beside-link/</link>
		<comments>http://stephenmcintyre.net/blog/image-beside-link/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 18:56:07 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=138</guid>
		<description><![CDATA[Today I&#8217;ll show you how to put an image beside external links on your site, or any other links for that matter. The effect is similar to the links in the References and External links sections of most Wikipedia pages.
Using the code below you will be able to create links like these, which show a [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ll show you how to put an image beside external links on your site, or any other links for that matter. The effect is similar to the links in the <a href="http://en.wikipedia.org/wiki/Web_site#References">References</a> and <a href="http://en.wikipedia.org/wiki/Web_site#External_links">External links</a> sections of most <a href="http://en.wikipedia.org/wiki/Web_site">Wikipedia pages</a>.<span id="more-138"></span></p>
<p>Using the code below you will be able to create links like <a href="/examples/linkimage/links.html">these</a>, which show a small icon beside each link with an <code>external</code> class. Notice that the local links still display normally as the CSS only changes those with <code>class="external"</code> and keeps the others in their original state. The <code>a:visited:hover</code> on line 15 is also an interesting effect to make note of, as it retains the <code>:hover</code> pseudo even on links referencing to visited sites, which wouldn&#8217;t show the hover state on one simply styled as <code>a:visited</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
a{
	color:#f90;
}
a:hover, a:visited:hover{
	color:#fc3;
}
a:visited{
	color:#740;
}
a.external{
	padding-right:18px;
	background:url(ext.gif) 100% 50% no-repeat;
}
a.external:hover, a.external:visited:hover{
	background-image:url(ext_hov.gif);
}
a:visited.external{
	background-image:url(ext_vis.gif);
}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#unv-loc&quot;</span>&gt;</span>Unvisited local link<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>Visited local link<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#unv-ext&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;external&quot;</span>&gt;</span>Unvisited external link<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;external&quot;</span>&gt;</span>Visited external link<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></td></tr></table></div>

<p><strong>Advanced</strong></p>
<p>For improved results, try combining all three images into one image strip and change your code to suit. This can be done by changing the <code>background-position</code> attribute in CSS. It&#8217;s the method I usually prefer as the strip is loaded on page load and doesn&#8217;t stall while the user hovers over the link. The change may not be as noticeable for a small image like this, but for larger images it can make a considerable difference.</p>
<p>Just remember that if your text will be a larger font size than the one I&#8217;m using you should allow more blank space between each image. If you get stuck, check <a href="/blog/navigation-bars-part-3-advanced-backgrounds">my tutorial on navigation bar backgrounds</a> for hints on using <code>background-position</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/image-beside-link/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Drop Down Menu &#8211; No JavaScript!</title>
		<link>http://stephenmcintyre.net/blog/css-dropdown-menu-no-javascript/</link>
		<comments>http://stephenmcintyre.net/blog/css-dropdown-menu-no-javascript/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 18:16:36 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=127</guid>
		<description><![CDATA[This time I&#8217;ll show you how to create your own drop down menu with XHTML and CSS, but with absolutely no Javascript! It&#8217;s all down to the CSS pseudo element :hover, which you have probably already used on anchor (&#60;a&#62;) tags. If you followed my previous tutorials on navigation bars you will definitely be familiar [...]]]></description>
			<content:encoded><![CDATA[<p>This time I&#8217;ll show you how to create your own drop down menu with XHTML and CSS, but with absolutely no Javascript! It&#8217;s all down to the CSS pseudo element <code>:hover</code>, which you have probably already used on anchor (<code>&lt;a&gt;</code>) tags. If you followed my <a href="/blog/navigation-bars-part-3-advanced-backgrounds/">previous tutorials on navigation bars</a> you will definitely be familiar with it. <span id="more-127"></span></p>
<p>The difference being that this time we use it on elements within a <a href="http://www.w3schools.com/TAGS/tag_dl.asp">definition list</a> (i.e. <code>&lt;dl&gt;</code>, <code>&lt;dt&gt;</code>, and <code>&lt;dd&gt;</code> tags). These are quite similar to <code>&lt;ul&gt;</code> and <code>&lt;li&gt;</code> tags, which again following the previous tutorials would help you in getting used to using them.</p>
<p>For an example, <a href="/examples/dropdown/main.html">click here</a> and see how it works. And as always, you&#8217;re free to download it and change the code to suit your own web site.</p>
<p>Also, I&#8217;ve posted the code below so you can see what&#8217;s involved without having to navigate away from the page. I&#8217;ve just put all of the code from the example page in one box and won&#8217;t explain it as it should be straight-forward enough. Pay particular attention to line 21 as that&#8217;s the line where the magic happens.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
div<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
dl<span style="color: #00AA00;">,</span> dt<span style="color: #00AA00;">,</span> dd<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
dl<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
dt<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
dd<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
dl<span style="color: #3333ff;">:hover </span>dd<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fb0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
dt a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
dd a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
p<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span>
&lt;div<span style="color: #00AA00;">&gt;</span>
    &lt;dl style<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;left:6px;&quot;</span><span style="color: #00AA00;">&gt;</span>
        &lt;dt<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#set-1&quot;</span><span style="color: #00AA00;">&gt;</span>Set <span style="color: #cc66cc;">1</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dt<span style="color: #00AA00;">&gt;</span>
        &lt;dd<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#link-1&quot;</span><span style="color: #00AA00;">&gt;</span>Link <span style="color: #cc66cc;">1</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dd<span style="color: #00AA00;">&gt;</span>
        &lt;dd<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#link-2&quot;</span><span style="color: #00AA00;">&gt;</span>Link <span style="color: #cc66cc;">2</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dd<span style="color: #00AA00;">&gt;</span>
    &lt;/dl<span style="color: #00AA00;">&gt;</span>
    &lt;dl style<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;left:112px;&quot;</span><span style="color: #00AA00;">&gt;</span>
        &lt;dt<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#set-2&quot;</span><span style="color: #00AA00;">&gt;</span>Set <span style="color: #cc66cc;">2</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dt<span style="color: #00AA00;">&gt;</span>
        &lt;dd<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#link-3&quot;</span><span style="color: #00AA00;">&gt;</span>Link <span style="color: #cc66cc;">3</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dd<span style="color: #00AA00;">&gt;</span>
        &lt;dd<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#link-4&quot;</span><span style="color: #00AA00;">&gt;</span>Link <span style="color: #cc66cc;">4</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dd<span style="color: #00AA00;">&gt;</span>
    &lt;/dl<span style="color: #00AA00;">&gt;</span>
    &lt;dl style<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;left:218px;&quot;</span><span style="color: #00AA00;">&gt;</span>
        &lt;dt<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#set-3&quot;</span><span style="color: #00AA00;">&gt;</span>Set <span style="color: #cc66cc;">3</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dt<span style="color: #00AA00;">&gt;</span>
        &lt;dd<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#link-5&quot;</span><span style="color: #00AA00;">&gt;</span>Link <span style="color: #cc66cc;">5</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dd<span style="color: #00AA00;">&gt;</span>
        &lt;dd<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#link-6&quot;</span><span style="color: #00AA00;">&gt;</span>Link <span style="color: #cc66cc;">6</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dd<span style="color: #00AA00;">&gt;</span>
    &lt;/dl<span style="color: #00AA00;">&gt;</span>
    &lt;dl style<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;left:324px;&quot;</span><span style="color: #00AA00;">&gt;</span>
        &lt;dt<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#set-4&quot;</span><span style="color: #00AA00;">&gt;</span>Set <span style="color: #cc66cc;">4</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dt<span style="color: #00AA00;">&gt;</span>
        &lt;dd<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#link-7&quot;</span><span style="color: #00AA00;">&gt;</span>Link <span style="color: #cc66cc;">7</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dd<span style="color: #00AA00;">&gt;</span>
        &lt;dd<span style="color: #00AA00;">&gt;</span>&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#link-8&quot;</span><span style="color: #00AA00;">&gt;</span>Link <span style="color: #cc66cc;">8</span>&lt;/a<span style="color: #00AA00;">&gt;</span>&lt;/dd<span style="color: #00AA00;">&gt;</span>
    &lt;/dl<span style="color: #00AA00;">&gt;</span>
&lt;/div<span style="color: #00AA00;">&gt;</span>
&lt;p<span style="color: #00AA00;">&gt;</span>
In publishing and graphic design<span style="color: #00AA00;">,</span> lorem ipsum is the name given to commonly used placeholder <span style="color: #993333;">text</span> to demonstrate the graphic elements of a document or visual presentation<span style="color: #00AA00;">,</span> such as <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">,</span> typography<span style="color: #00AA00;">,</span> and layout. Substituting this dummy <span style="color: #993333;">text</span> for meaningful <span style="color: #000000; font-weight: bold;">content</span> should not be confused with &amp;quot<span style="color: #00AA00;">;</span>greeking&amp;quot<span style="color: #00AA00;">;</span>.
&lt;/p<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>Enjoy messing around with it <img src='http://stephenmcintyre.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/css-dropdown-menu-no-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Navigation Bars Part 3 &#8211; Advanced Backgrounds</title>
		<link>http://stephenmcintyre.net/blog/navigation-bars-part-3-advanced-backgrounds/</link>
		<comments>http://stephenmcintyre.net/blog/navigation-bars-part-3-advanced-backgrounds/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 12:30:52 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=71</guid>
		<description><![CDATA[Following on from my other two tutorials, this time I&#8217;ll show you a simple technique to display background images in your tabs with a simple hover over/out effect without Javascript.
Example 1
The HTML and CSS for this tutorial will be taken from the list-styled horizontal nav bar in the first tutorial, so I&#8217;ll just show the [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from my other two tutorials, this time I&#8217;ll show you a simple technique to display background images in your tabs with a simple hover over/out effect without Javascript.<span id="more-71"></span></p>
<p><a href="/examples/nav/advanced-bgs/1/list.html"><strong>Example 1</strong></a></p>
<p>The HTML and CSS for this tutorial will be taken from the list-styled horizontal nav bar in the first tutorial, so I&#8217;ll just show the extra required CSS here.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#nav</span> a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">tab_out.gif</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">tab_over.gif</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>So, this was all I added to the relevant styles in the original document to make it work. Two images <code>tab_out.gif</code> and <code>tab_over.gif</code> have to be created and thrown into the same folder as the html file for it to work. You can steal mine if you like, or create another pair of similar 144&#215;19 GIF images.</p>
<div class="wp-caption aligncenter" style="width: 154px"><a href="/examples/nav/advanced-bgs/1/tab_out.gif"><img alt="tab_out.gif" src="/examples/nav/advanced-bgs/1/tab_out.gif" title="tab_out" width="144" height="19" /></a><p class="wp-caption-text">tab_out.gif</p></div>
<div class="wp-caption aligncenter" style="width: 154px"><a href="/examples/nav/advanced-bgs/1/tab_over.gif"><img alt="tab_over.gif" src="/examples/nav/advanced-bgs/1/tab_over.gif" title="tab_over" width="144" height="19" /></a><p class="wp-caption-text">tab_over.gif</p></div>
<p><a href="/examples/nav/advanced-bgs/2/list.html"><strong>Example 2</strong></a></p>
<p>This isn&#8217;t a perfect solution, though, because the hover state image could take a few seconds to load on slow connections, or even on fast ones depending on what you get the file size down to. So what we want to do is load it as soon as the page does, so when the user hovers the mouse over our tabs they see the hovered image straight away.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#nav</span> a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">tab.gif</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>So this time I&#8217;ve combined <code>tab_out.gif</code> and <code>tab_over.gif</code> into one image, one on top of the other. Now when we hover over it, the <code>background-position</code> attribute &#8216;moves&#8217; the image that&#8217;s already been loaded on your page halfway down, instead of loading up another one onto the page. The <code>0 100%</code> part means it moves it 100% vertically and shows the orange half. An exact movement of <code>0 -19px</code> would work equally as well.</p>
<div class="wp-caption aligncenter" style="width: 154px"><a href="/examples/nav/advanced-bgs/2/tab.gif"><img alt="tab.gif" src="/examples/nav/advanced-bgs/2/tab.gif" title="tab" width="144" height="38" /></a><p class="wp-caption-text">tab.gif</p></div>
<p><a href="/examples/nav/advanced-bgs/3/list.html"><strong>Example 3</strong></a></p>
<p>But I&#8217;m still not happy. I want it to load even faster than that, and I&#8217;m sure given the option you do too. So how do we do that? Well we shrink the image.</p>
<p>This time I have taken the 144&#215;38 GIF from the last example and shrunk it horizontally to just 1px wide. Now, by default CSS should show it okay as soon as you change the size of it, but I&#8217;ve written the CSS differently below to make it look a lot simpler, and could be good practice for you to use this yourself. You can cram the background colour and image URL, repetition and position into one <code>background</code> attribute to make things much easier, like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#nav</span> a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">tab.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>So there you go, three different ways of displaying hover-over backgrounds for your navigation bar. I know which one I prefer, but like most code examples it always depends on your own project and the use it&#8217;s intended for.</p>
<p>All resources can be downloaded from <a href="/examples/">the examples folder</a>, with this particular topic&#8217;s resources filed under <a href="/examples/nav/advanced-bgs/">advanced-bgs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/navigation-bars-part-3-advanced-backgrounds/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Navigation Bars Part 2 &#8211; Simple Vertical</title>
		<link>http://stephenmcintyre.net/blog/navigation-bars-part-2-simple-vertical/</link>
		<comments>http://stephenmcintyre.net/blog/navigation-bars-part-2-simple-vertical/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 15:30:51 +0000</pubDate>
		<dc:creator>Stephen McIntyre</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://stephenmcintyre.net/?p=67</guid>
		<description><![CDATA[This time I&#8217;ll show you how to make your own vertical navigation bar complete with similar effects as before, and thankfully just about as simple. The final compiled code should produce this page.
If you followed the horizontal nav bar tutorial you&#8217;ll find this to be a very simple transition, as there&#8217;s very little difference in [...]]]></description>
			<content:encoded><![CDATA[<p>This time I&#8217;ll show you how to make your own vertical navigation bar complete with similar effects as before, and thankfully just about as simple. The final compiled code should produce <a href="/examples/nav/simple-vertical/simple.html">this page</a>.<span id="more-67"></span></p>
<p>If you followed the <a href="/blog/navigation-bars-part-1-simple-horizontal/">horizontal nav bar tutorial</a> you&#8217;ll find this to be a very simple transition, as there&#8217;s very little difference in code. If you didn&#8217;t, it might be worth your while to as it will help to understand this one a bit better.</p>
<p>The CSS consists of:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#container</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fd5</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#e80</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">144px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fb0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
.<span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
br<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>It has a few additions to before.</p>
<p>The <code>container</code> attributes are just to show it more in the context of being in a page. For the navigation bar to work you don&#8217;t actually need it, so you can remove this set of styles and its corresponding <code>div</code> from the below lines of code. Likewise, the <code>clear</code> class attribute of <code>clear:both</code> is only needed for this div, but is useful to make note of when you put this code into your own site as it fixes things like divs not stretching to the height they should be.</p>
<p>The <code>nav</code> element has been reduced to <code>150px</code> wide as we will only need it to be as big as that number, but as usual you can change your own code to suit.</p>
<p>The <code>br</code> tag attribute is new but is only important in making the list show properly with styles disabled and in some mobile browsers.</p>
<p>HTML:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nav&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link1&quot;</span>&gt;</span>Link 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link2&quot;</span>&gt;</span>Link 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link3&quot;</span>&gt;</span>Link 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link4&quot;</span>&gt;</span>Link 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clear&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Looks familiar doesn&#8217;t it. Stripped of the line breaks (<code>&lt;br&gt;</code> tags) the code&#8217;s identical to what we had for the horizontal links (apart from the <code>container</code> and <code>clear</code> divs but as I said before, we don&#8217;t necessarily need those).</p>
<p>All the stuff in there should be pretty straight forward, especially if you&#8217;ve already looked at the previous tutorial, so I&#8217;ll move swiftly onto the next part.</p>
<p>The result:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
#container{
	margin:auto;
	width:600px;
	background-color:#fd5;
	border:2px solid #e80;
}
#nav{
	width:150px;
}
#nav a{
	display:block;
	float:left;
	width:144px;
	background-color:#eee;
	border:3px solid #555;
	text-align:center;
	text-decoration:none;
	color:#000;
}
#nav a:hover{
	background-color:#fb0;
}
.clear{
	clear:both;
}
br{
	display:none;
}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nav&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link1&quot;</span>&gt;</span>Link 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link2&quot;</span>&gt;</span>Link 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link3&quot;</span>&gt;</span>Link 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link4&quot;</span>&gt;</span>Link 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clear&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>So just bung this into your favourite HTML editor and have a mess about with it and see what you can come up with.</p>
<p><strong>Note:</strong> if you view the page that I linked to above in IE it aligns the container to the left instead of centring it like in other browsers. This is due to it not being contained in a <code>&lt;body&gt;</code> tag (which I&#8217;m assuming you know about and are using along with the code in these tutorials, and not just the code on its own). So just add your normal page tags and it will fix itself.</p>
<p><strong>Other example:</strong><br />
Also similar to my last tutorial is a listed style alternative. It can be achieved with similar methods and should look like <a href="/examples/nav/simple-vertical/list.html">this</a> when you&#8217;re done.</p>
<p>Replace the <code>#nav</code> styles with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#nav</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p><strong>Note:</strong> you won&#8217;t need the <code>br</code> tag styles for this version, so you can remove them if you like.</p>
<p>Replace the HTML with the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nav&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link1&quot;</span>&gt;</span>Link 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link2&quot;</span>&gt;</span>Link 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link3&quot;</span>&gt;</span>Link 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#link4&quot;</span>&gt;</span>Link 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clear&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>And you&#8217;re done. So now you can add two types of navigation bars to your site in two variations a-piece. Spoiled for choice really.</p>
]]></content:encoded>
			<wfw:commentRss>http://stephenmcintyre.net/blog/navigation-bars-part-2-simple-vertical/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
