<?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>Paul Bennett - User Interface Developer &#187; jQuery</title>
	<atom:link href="http://pmbennett.net/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://pmbennett.net</link>
	<description></description>
	<lastBuildDate>Thu, 27 Oct 2011 15:10:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introducing Plushash39</title>
		<link>http://pmbennett.net/2010/06/02/introducing-plushash39/</link>
		<comments>http://pmbennett.net/2010/06/02/introducing-plushash39/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 13:49:14 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[clipboard]]></category>
		<category><![CDATA[entites]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=393</guid>
		<description><![CDATA[As a user interface developer, I come across those annoying question marks in Firefox fairly frequently, where someone has copied-and-pasted some text from a rich-text editor into an HTML file which contained unencoded HTML character entities. I have a fairly good memory for these things, but inevitably I have to use Google to find some that escape my memory. So I developed a simple HTML application to copy the encoded HTML character entities to my clipboard, ready to be pasted directly into my HTML.]]></description>
			<content:encoded><![CDATA[<p>The site is still in Beta, which means there are probably a few bugs loitering here and there. I have tested it in a number of browsers and it seems to work pretty well. I think the large type helps to find the exact charcter you need, and the one-click copy-and-paste saves having to highlight some tiny text (as I would have done previously). </p>
<p><a class="btn visit_link_btn" href="http://plushash39.com">HTML charcter entity copy-and-paste</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/06/02/introducing-plushash39/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CSS3 Animated Photo Stack with jQuery</title>
		<link>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/</link>
		<comments>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/#comments</comments>
		<pubDate>Fri, 28 May 2010 11:51:42 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Transitions Webkit]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=377</guid>
		<description><![CDATA[CSS3 transitions and animations are rightly attracting a lot of attention. With support in most modern browsers, there is a lot of scope for creating rich user experiences using only CSS. In this post, I will walk through how to create a stack of photos using CSS keyframe animations and a dash of jQuery to achieve a pretty awesome effect.]]></description>
			<content:encoded><![CDATA[<p>So, lets dive straight in! The markup is pretty straightforward, you just need a container filled with the images for the stack of photos:</p>
<pre><code>&lt;div id="photo_stack"&gt;
	&lt;img id="photo1" src="images/photostack1.jpg" alt="Alt text goes here..." /&gt;
	&lt;img id="photo2" src="images/photostack2.jpg" alt="Alt text goes here..." /&gt;
	&lt;img id="photo3" src="images/photostack3.jpg" alt="Alt text goes here..." /&gt;
&lt;/div&gt;</code></pre>
<p>You will then need some simple CSS to style and position the images in a stack. We will be using jQuery to alter the z-index values of each image once the animation has completed, so we will start by giving each image a high z-index value. You will also need to setup the speed and easing functions for the transitions. </p>
<pre><code>#photo_stack img {
	position: absolute;
	border: 10px solid #FFF;
	box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	-moz-box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	-webkit-box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	z-index: 9999;

	/* setup transition speed and easing */
	-moz-transition: all 0.2s ease; /* Firefox */
	-webkit-transition: all 0.2s ease; /* WebKit */
	-o-transition: all 0.2s ease; /* Opera */
	transition: all 0.2s ease; /* Standard */

}
#photo_stack #photo1 {
	top: 0;
	left: 100px;
}
#photo_stack #photo2 {
	top: 12px;
	left: 55px;
}
#photo_stack #photo3 {
	top: 27px;
	left: 50px;
}</code></pre>
<p>Once this is complete you can add the CSS to create the keyframe animation, which will take the image at the top of the stack and place it at the bottom of the photo stack.</p>
<pre><code>@-webkit-keyframes shuffle {
	0% {
		margin-left: 0px;
	}
	50% {
		margin-left: 450px;
		-webkit-transform: scale(0.9);
		-moz-transform: scale(0.9);
		transform: scale(0.9);
	}
	100% {
		margin-left: 0px;
		-webkit-transform: scale(1);
		-moz-transform: scale(1);
		transform: scale(1);
	}
}
#photo_stack .animate {
	-webkit-animation-name: shuffle;
	-webkit-animation-duration: 1s;
	-webkit-animation-iteration-count: 1;
}</code></pre>
<p>What this is basically doing, is running the keyframe animation called &#8217;shuffle&#8217; once and for a duration of 1 second. The animation itself is moving the image 450px to the right of the stack, scaling down to give an impression of depth, and then moving it back to where it&#8217;s original position. Note that this will only happen when the image is assigned the &#8216;animate&#8217; class.</p>
<p>Okay, so you now have a cool animation effect, but nothing triggers it and the image does not go to the bottom of the stack: Enter jquery. What jquery will do, is trigger the animation by assigning the &#8216;animate&#8217; class to the image on the top of the stack, removing it once the animation is complete. </p>
<pre><code>$imgs = $("#photo_stack img");
$imgCount = $imgs.length;
$curr_index = 0;
$imgs.last().addClass('current'); /* Set the image at top of stack to current */

$("#photo_stack")
	.delegate('img', 'click', function() {
		$this = $(this);

		/* If the image is at the top of the stack */
		if ($this.hasClass('current')) {
			/* Work out new z-index value */
			$zi = $this.css('zIndex') - $imgCount;

			/* Trigger animation */
			$this.addClass('animate');

			/* Assign new z-index value then stop animation after complete */
			setTimeout(function() { $this.css('zIndex', $zi); }, 200);
			setTimeout(function() { $this.removeClass('animate'); }, 1000);

			/* Set next image to current */
			$this.removeClass('current');
			if ($this.index() == 0) {
				$imgs.last().addClass('current');
			} else {
				$imgs.eq($this.index()-1).addClass('current');
			}
		}
	})</code></pre>
<p>You will now have some images in a stack that you can click on and they will be animated and placed to the bottom of the stack. Now it is time to use the rotation transition to make the photo stack look a little more realistic. I used CSS classes to rotate the images somewhere between -4 and 4 degrees and used jQuery to randomly assign one of those classes to each image when the DOM has loaded. Then I just added a CSS rule to rotate the image to 0 degrees on hover. </p>
<pre><code>#photo_stack .deg1 {
	-webkit-transform: rotate(1deg);
   	-moz-transform: rotate(1deg);
   	transform: rotate(1deg);
}
#photo_stack .deg2 {
	-webkit-transform: rotate(2deg);
   	-moz-transform: rotate(2deg);
   	transform: rotate(2deg);
}
#photo_stack .deg3 {
	-webkit-transform: rotate(3deg);
   	-moz-transform: rotate(3deg);
   	transform: rotate(3deg);
}
#photo_stack .deg4 {
	-webkit-transform: rotate(4deg);
   	-moz-transform: rotate(4deg);
   	transform: rotate(4deg);
}
#photo_stack .deg1neg {
	-webkit-transform: rotate(-1deg);
   	-moz-transform: rotate(-1deg);
   	transform: rotate(-1deg);
}
#photo_stack .deg2neg {
	-webkit-transform: rotate(-2deg);
   	-moz-transform: rotate(-2deg);
   	transform: rotate(-2deg);
}
#photo_stack .deg3neg {
	-webkit-transform: rotate(-3deg);
   	-moz-transform: rotate(-3deg);
   	transform: rotate(-3deg);
}
#photo_stack .deg4neg {
	-webkit-transform: rotate(-4deg);
   	-moz-transform: rotate(-4deg);
   	transform: rotate(-4deg);
}
#photo_stack .hover {
	-webkit-transform: rotate(0deg);
   	-moz-transform: rotate(0deg);
   	transform: rotate(0deg);
	cursor: pointer;
}</code></pre>
<p>I chose to use this approach, as it means that you can have any number of images in the stack, and they will be randomly rotated. If you wanted, you could just assign a specific angle to each photo in the stack using each images ID for complete control.</p>
<p>The full code for the animated photo stack can be found on the <a href="/demos/css3-animated-photo-stack.html">demo page</a>. It works best in the latest version of Chrome or Safari. Firefox works but without the animation and I did not even bother checking Internet Explorer &#8211; it always spoils the party!</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rotating Globe with jQuery</title>
		<link>http://pmbennett.net/2010/04/20/rotating-globe-with-jquery/</link>
		<comments>http://pmbennett.net/2010/04/20/rotating-globe-with-jquery/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 21:11:55 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=288</guid>
		<description><![CDATA[<p>This is basically another take on moving backgrounds using jQuery, but I was inspired to create a rotating globe by <a href="http://www.romancortes.com/blog/pure-css-coke-can/">Rom&#225;n Cort&#233;s Pure CSS Coke Can</a>. Sure, this has nothing to do with displacement, and it uses JavaScript, but it was fun none-the-less!</p>]]></description>
			<content:encoded><![CDATA[<p>As I mentioned above, this is yet another moving background example, there is nothing new here, I just thought it might be fun to try!</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/04/20/rotating-globe-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Picture Board</title>
		<link>http://pmbennett.net/2010/04/13/jquery-picture-board/</link>
		<comments>http://pmbennett.net/2010/04/13/jquery-picture-board/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 21:25:22 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Flip]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=299</guid>
		<description><![CDATA[<p>I'm very much looking forward to the World Cup this year, which reminded me of the fun I had during the last one four years ago. I remember organising a Question of Sport style quiz for my fellow colleagues, which gave me a great chance to try out some JavaScript that I had learned. One round involved the creation of a picture board, which is divided up into squares, and users can click on the numbers to reveal a portion of an image underneath, similar to the Picture board on Question of Sport, but more like a game of Catchphrase. It got me thinking: what would I do now I am armoured with all this jQuery goodness?</p>
]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://webmuch.com/image-flip-using-jquery/">Aayush Shastri&#8217;s image flip</a>, I decided to re-create the picture board using some cool animation. My approach was to use a simple list of links, which would each take the form of a square on top of the background image. The HTML and CSS are very straight forard, so I will not list that here. Instead, I will walk through my solution using jQuery.</p>
<p>Before I begin, it is worth highlighting that I am using an ordered list of links, and the hidden image is a background image on the <code>&lt;ol&gt;</code> element. I will take the following approach:</p>
<ol>
<li>Store the url of the hidden image</li>
<li>Add an element to each list item, which will be used to display the hidden portion of the image</li>
<li>then add the click events to the numbered square and the reveal element</li>
</ol>
<p>So the first few lines set a few variables, allowing us to cache some jQuery objects for later use.</p>
<pre><code>$gridWrap = $('#reveal_grid');
$revealImg = $gridWrap.css('background-image');
$gridWrap.css('background', 'transparent')
$sqrs = $('#reveal_grid li');</code></pre>
<p>We then loop through the links in the list and add the <code><span></code> elements, add some CSS rules to setup the hide/reveal.</p>
<pre><code>$('#reveal_grid li a').each(function() {
	$num = $(this);
	$bgPos = $num.css('backgroundPosition');
	$num.parent('li').append(
		$('<span class="reveal"></span>').css({
			backgroundImage: $revealImg,
			backgroundPosition: $bgPos,
			height:'0',
			marginTop: ($num.height()/2) + 'px',
			opacity:'0.2'
		})
	);
});</code></pre>
<p>Next we need to add the click events, which just adds the flip animation that was based upon the <a href="http://webmuch.com/image-flip-using-jquery/">original by Aayush Shastri</a>:</p>
<pre><code>$sqrs.delegate('a', 'click', function() {
	$sqr = $(this);
	$height = $sqr.height();
	$width = $sqr.width();
	$sqr.stop()
	.animate({
		width: $width + 'px',
		height: '0',
		marginTop: ($height/2) + 'px',
		opacity: '0.2'
	}, 500, function() {
	$sqr.next('.reveal')
		.stop()
		.animate({
			width: $width + 'px',
			height: $height + 'px',
			marginTop: '0',
			opacity: '1'
		}, 500);
	});
	return false;
});
$sqrs.delegate('span', 'click', function() {
	$sqr = $(this);
	$height = $sqr.height();
	$width = $sqr.width();
	$sqr.stop()
	.animate({
		width: $width + 'px',
		height: '0',
		marginTop: ($height/2) + 'px',
		opacity: '0.2'
	}, 500, function() {
		$sqr.prev('a')
		.stop()
		.animate({
			width: $width + 'px',
			height: $height + 'px',
			marginTop: '0',
			opacity: '1'
		}, 500);
	});
	return false;
});</code></pre>
<p>I am aware that this code could be streamlined somewhat, but it made sense to structure it like this for demonstration purposes. In terms of performance, it seems fine, so I will leave as is for the time being.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/04/13/jquery-picture-board/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto-fit Tabs</title>
		<link>http://pmbennett.net/2010/03/26/auto-fit-tabs/</link>
		<comments>http://pmbennett.net/2010/03/26/auto-fit-tabs/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 18:57:44 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tabs]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=229</guid>
		<description><![CDATA[<p>A while ago, over at <a href="http://www.bright-interactive.co.uk">Bright Interactive</a>, we had a client with a challenging requirement: they wanted a tabbed area on a page, which would have multiple rows of tabs. The challenging part came about when they requested that the tabs would automatically fill their containing box. That was still pretty easy to achieve, until I realised that the website had a fluid layout, and so the width of the containing box was not defined in pixels in the CSS stylesheet.</p>]]></description>
			<content:encoded><![CDATA[<p>The website couldn&#8217;t use a javascript library, so it had to be done completely from scratch. It was a bit fiddly, especially with browser inconsistencies when it came to rounding widths of containers, but I got there eventually. It got me wondering how much easier this would be to achieve using jQuery.</p>
<div class="img_wrapper"><img src="http://resources.pmbennett.net/demos/images/tabs_diagram.png" alt="Diagram of autofit tabs concept" /></div>
<p>The Markup and CSS is pretty straight forward: We just use a list of links that are floated to achieve the horizontal tabs. This is a pretty standard appraoch, so I won&#8217;t list that code here as it is unecessary.</p>
<p>Now the tricky part: the jQuery. Before writing the JavaScript, I wanted to have a clear approach to solving this problem. Basically, every time the page loads or the window is resized, the following steps must take place:</p>
<ol>
<li>Find the width of the tabs&#8217; containing element</li>
<li>Determine how many rows there will be and what row each tab will be in</li>
<li>Determine the amount of space left on each row, and from that work out how much padding to add to each tab to make them fill the space</li>
<li>Add the extra padding to each tab</li>
<li>Do any extra +/- of pixels to accommodate browser rounding inconsistencies</li>
</ol>
<p><em>There are also a few other things that needed to be done in order to get around the browser inconsistencies with working out dimensions, but I will explain them when we get to it.</em></p>
<p>To begin with, we setup the load and window resize events and also make any whitespace in the link text a non-breaking space. This is necessary to prevent the text from dropping onto two lines when resizing.</p>
<pre><code>$(function() {
	$("#tab_container li a").html(function(index, htm) {
		return htm.replace(/\s/g, '&amp;nbsp;');
	});
	autoSizeTabs();
	$(window).resize(function() {
		autoSizeTabs();
	});
});
function autoSizeTabs() {
	// add code here...
}</code></pre>
<p>Now for the fun part, the code that actually makes the tabs fit their container. To start with, we just set a few variables which will be used throughout. the main one is the width of the tab container. I have also added some code to reset the tabs to their default state, otherwise it will break if the function is called more than once. (I.e. when someone is testing by constantly resizing the browser).</p>
<pre><code>// Reset the tabs to their default state
$("#tab_container li").css({"width": "auto", "borderRightWidth": "1px"});
$("#tab_container li:last-child").css({'borderRightWidth': '0px'});
$("#tab_container").parent().css({"width": "50%"});

// Setup some variables
var containerWidth = $("#tab_container").innerWidth();
var tabsWidth = 0;
var rowCount = 1;</code></pre>
<p>As outlined in the steps above, we then need to loop through the list-items to determine which row each should be on. In this implementation, I decided to make use of a class name which takes the form of &#8220;tab_row_X&#8221;. I did play with the idea of using jQuery&#8217;s data() method for this, but it seemed more tricky to retrieve that value, so I decided against it.</p>
<pre><code>// Go through tabs and work out how many rows there are and which tabs are on which row
$("#tab_container li").each(function() {
	tabsWidth = tabsWidth + $(this).outerWidth();
	if (tabsWidth &gt; containerWidth) {
		tabsWidth = 0;
		rowCount++;
	}
	$(this).addClass('tab_row_'+rowCount);
});</code></pre>
<p>With the above in place, we are now ready to pad-out the tabs to make them fit to the width of their parent node. To do this we loop through each row of tabs and work out how much space (in pixels) the tabs use up, and subtract it from the width of the parent container to find the amount of space left over. Then we just divide that by the number of tabs. It is important to note, that I used Math.round() here which means that there could be too much or too little padding added, which will need to be addressed later. (Browser inconsistencies with rounding decimal dimensions meant that I had to make these whole numbers at this stage).</p>
<pre><code>// Now go through the tabs in each row and pad them out to fill the container
for (var d=1; d&lt;=rowCount; d++) {
	var row = $(".tab_row_"+d);
	var rowWidth = 0;

	// Work out the space left over in the row
	for (var r=0; r&lt;$(row).length; r++) {
		rowWidth = rowWidth + $(row[r]).outerWidth();
	}
	var pxDiff = containerWidth - rowWidth;
	tabExtraPx = Math.round(pxDiff / $(row).length);

	// Now add the extra padding to each of the tabs in the row
	var newWidth = 0;
	$(".tab_row_"+d+":last").css({'borderRightWidth': '0px'});
	$(row).each(function() {
		var wd = $(this).outerWidth() + tabExtraPx;
		var cssWd = $(this).innerWidth() + tabExtraPx;
		$(this).css({'width': cssWd + 'px'});
		newWidth = newWidth + wd;
	});

	// Rest of code goes here...
}</code></pre>
<p>Once that is complete, we then need to address any differences caused by the rounding. This just works out the overall width of the tabs and compares it to the width of the container, adding or subtracting the difference.</p>
<pre><code>// Now deal with any difference left as a result of rounding
if (newWidth &gt; containerWidth) {
	var diff = newWidth - containerWidth;
	var lastTab = $(".tab_row_"+d+":last");
	var nWidth = Math.round($(lastTab).innerWidth() - diff);
	var row = $(lastTab).css({'width': nWidth+'px'});;
}
if (newWidth &lt; containerWidth) {
	var diff = containerWidth - newWidth;
	var lastTab = $(".tab_row_"+d+":last");
	var nWidth = Math.round($(lastTab).innerWidth() + diff);
	var row = $(lastTab).css({'width': nWidth+'px'});;
}</code></pre>
<p>Once we have resized the tabs, We need to remove the class used to identify which row each was on, so that if the function gets called again, the tabs will be in their default state.</p>
<pre><code>// reset the row class
$("#tab_container li").removeClass("tab_row_"+d);</code></pre>
<p>Lastly, we need to set the width, in pixels, of the parent container, otherwise we will again come across inconsistenices with browser dimension rounding if the width is actually a decimal number.</p>
<pre><code>// Fix the width of the container to get around browser rounding issues
$("#tab_container").parent().css({"width": containerWidth+'px'});</code></pre>
<p>Although this solution does work, it doesnt evenly spread the tabs across rows. It merely works out what row a tab is one and applies the necessary padding to make them fit their container. So there will be circumstances where one tab drops to a new row and fills the entire row. It&#8217;s not ideal, but it satisfied my requirements at the time.<br />
The code is also far from optimal, and I&#8217;m sure there are some improvements that can be made, but I don&#8217;t particularly have the desire to expend any more time on this right now.</p>
<p>Tested in Firefox 3+, IE6+ (IE6 seems to work 99% of the time, but very occaisonally mis-calculates the widths), Chrome, Safari (Win).</p>
<p class="article_links"><a href="/demos/autofit-tabs.html" target="_blank">View demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/03/26/auto-fit-tabs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrapping lines of text using jQuery</title>
		<link>http://pmbennett.net/2010/03/03/wrapping-lines-of-text-using-jquery/</link>
		<comments>http://pmbennett.net/2010/03/03/wrapping-lines-of-text-using-jquery/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 17:53:16 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=254</guid>
		<description><![CDATA[<p>Not long ago, I entered Chris Coyier's <a target="_blank" href="http://css-tricks.com/the-great-css-off-giveaway/">CSS-Off</a> competition. The mock-up was deceivingly harder than it looked, but I managed to put something together that I think should stand a chance of being considered for a prize. The one area that gave me trouble was the use of different colours on different lines of text within an element. I knocked together a quick jQuery plugin to achieve this, and then realised after submitting my entry that it didn't work at all in Internet Explorer. Doh! Anyways, I have now fixed that, and here is the plugin.</p>]]></description>
			<content:encoded><![CDATA[<p>I am not going to go through the code in this post as it is pretty trivial. Essentially, all you need to do is go through each word in block of plain text, wrap it in an inline element, (e.g. a span) then work out each of those element&#8217;s top offset from their containing element. By doing this, you can work out which line each word is on. Lastly, you can wrap each line in an element, which can then be styled. Simples!</p>
<p>However, I feel it is worth mentioning a weird IE7/8 bug that I encountered along the way.  Basically, when I wrapped each word in span, the first word of each line had an incorrect top offset. In fact, the offset was equal to that of an element on the previous line. There didn&#8217;t seem to be any logical reason for this to be happening, other than a browser bug. A quick workaround later and the plugin works in all major browsers.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/03/03/wrapping-lines-of-text-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixed Scrolling Navigation</title>
		<link>http://pmbennett.net/2010/02/09/fixed-scrolling-navigation/</link>
		<comments>http://pmbennett.net/2010/02/09/fixed-scrolling-navigation/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 18:09:30 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Navigation]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=232</guid>
		<description><![CDATA[<p>Recently, I was faced with the requirement to make a horizontal navigation bar fixed to the top of browser window, but only when the user scrolls past it. I had a quick Google around, and found a few plugins that did way more than I needed them to. I was certain this could be achieved in a couple of lines using jQuery, so I did it myself.</p>]]></description>
			<content:encoded><![CDATA[<p>The structure of the HTML was as follows:</p>
<pre><code>&lt;header class="centered"&gt;
  Header markup goes here
&lt;/header&gt;
&lt;div id="main_content"&gt;
  Content goes here
&lt;/div&gt;
&lt;div id="nav_bar"&gt;
  Navigation goes here
&lt;/div&gt;</code></pre>
<p>I used CSS to position the navigation absolutely in between the header and the main content, and then wrote a small amount of jQuery to do the rest.</p>
<pre><code>$(document).ready(function() {
	var yOffset = $("#nav_bar").offset().top;
	$(window).scroll(function() {
		if ($(window).scrollTop() &gt; yOffset) {
			$("#nav_bar").css({
				'top': 0,
				'position': 'fixed'
			});
		} else {
			$("#nav_bar").css({
				'top': yOffset + 'px',
				'position': 'absolute'
			});
		}
	});
});</code></pre>
<p>This piece of JavaScript starts by finding the offset of the navigation from the top of the document. Then, it defines the scroll event for the window object, which checks to see if the window has been scrolled past the navigation element. If this has occurred, it fixes the navigation to the top of the window. If not, the navigation is returned to it&#8217;s default state.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/02/09/fixed-scrolling-navigation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animated Backgrounds with jQuery</title>
		<link>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/</link>
		<comments>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 18:37:40 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=230</guid>
		<description><![CDATA[<p>I apologise in advance, a this is a very old technique, but it's something I have wanted to try out since last year. A while ago, I stumbled upon <a href="http://www.sunrisedesign.com/" target="_blank">Sunrise Design</a>, and absolutely loved the subtle background animation!</p>]]></description>
			<content:encoded><![CDATA[<p>Of course, this has been done many times before, but not in such an ethereal manner. So I have put together a not-so-subtle demo to have a go at this myself. I am not going to post the code here as this is very simple to achieve and hardly ground-breaking! If you want to see how this effect is achieved, you can view the source code of the demo.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance on pmbennett.net</title>
		<link>http://pmbennett.net/2009/11/12/performance-on-pmbennett-net/</link>
		<comments>http://pmbennett.net/2009/11/12/performance-on-pmbennett-net/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 12:49:10 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=209</guid>
		<description><![CDATA[Whilst designing the new skin for this site, I made the decision to go for a single page layout with a few other templates for the archive, portfolio and articles pages. I didn't really consider the impications of this for the speed at which my page loads until I read <a href="http://css-tricks.com/images-on-a-subdomain/">Chris Coyier's article about serving images from a subdomain</a>. That got me thinking, especially with all the imagery I was going to need to use. So I had a think about what things I could do to either reduce the size of the page, reduce the number of requests and generally speed things up. Here are three steps I took to do this, which have actually shaved an average of 4 seconds off the page load time.]]></description>
			<content:encoded><![CDATA[<h5>Let Google host your jQuery files</h5>
<p>The jQuery library is one of many libraries hosted by <a href="http://code.google.com/apis/ajaxlibs/">Google AJAX Libraries</a>. Up until this redesign, I had thought nothing of downloading the latest version, uploading it to my webserver and including it as usual in the document head. However, after reading a number of articles about browsers limiting the number of simultaneous connections, it was obvious that using the files hosted by Google will free up connections for other resources to be downloaded.</p>
<p>This isn&#8217;t the only benefit of using files hosted by Google. Google&#8217;s Content Delivery Network (CDN) means that anyone anywhere in the world can view the page and not have to endure the increased latency of downloading the resources from my single web server (which could be half the world away!). Not only that, but if other sites use Google&#8217;s AJAX libraries, then these files will be cached in many people&#8217;s browsers already! So they won&#8217;t even need to download them!</p>
<h5>Serve Resources from a Subdomain</h5>
<p>This was obviously the reason why I began look into the performance of my site. I have already explained how browsers limit the number of simultaneous connections, so setting up a subdomain that points to the directory on your server where your images are stored will trick the browser into thinking they are stored on a different domain. As previously stated, this wil free up connections so that other resources can be downloaded, thus decreasing the overall time taken to download all resources that make up the page.</p>
<h5>Image Sprites</h5>
<p>I have been using this technique for years now, but it is still worth mentioning as it really can have a big impact on the number of requests made when loading a page. For example, when I first created the skin for my site, I used no sprites and there were 36 separate requests made by the browser. After generating a few image sprites, I managed to reduce the amount of requests to 28!</p>
<h5>To wrap up&#8230;</h5>
<p>The below screenshot shows the Net panel in Firebug when loading my site in Firefox. As you can see I have jQuery hosted by Google; images and Javascript files are served from resources.pmbennett.net; and the stylesheets are served from pmbennett.net. As I mentioned at the beginning, this has shaved 4 seconds off the average page load speed!</p>
<p><img src="http://resources.pmbennett.net/demos/images/performance.png" alt="Screenshot of Firebug Net panel" /> </p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2009/11/12/performance-on-pmbennett-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Bar Chart with jQuery</title>
		<link>http://pmbennett.net/2009/08/20/css-bar-chart-with-jquery/</link>
		<comments>http://pmbennett.net/2009/08/20/css-bar-chart-with-jquery/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 15:12:00 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://pmbennett.net/articles/?p=75</guid>
		<description><![CDATA[I saw a flash bar chart the other day, which had a nice animation and looked very nice, and wondered if it would be possible to achieve a similar effect using just XHTML, CSS and a little bit of jQuery.]]></description>
			<content:encoded><![CDATA[<h4>Step 1: The Markup</h4>
<p>I started with a simple ordered list, which contained the text values which would represent the height of each bar on the chart. there are wrapped in a span which we will require in order to style this correctly in the CSS. </p>
<pre><code>&lt;div id="chart"&gt;
&lt;ol&gt;
	&lt;li id="green_bar"&gt;<span>450</span>&lt;/li&gt;
	&lt;li id="yellow_bar"&gt;<span>600</span>&lt;/li&gt;
	&lt;li id="red_bar"&gt;<span>300</span>&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</code></pre>
<h4>Step 2: The <abbr title="Cascading Style sheets">CSS</abbr></h4>
<p>I then used some background images to create the graph and the 3D bars. The CSS specifies how high each bar should be and adds the background images. (This can be quite tricky as it requires a little bit of arithmetic to ensure that the bar is the correct height and the scales are consistent).</p>
<pre><code>#chart {
	background: #FFF url('../images/chart_bg.png') no-repeat 0 0;
	width: 636px;
	height: 420px;
}
#chart ol {
	margin: 0;
	padding: 0;
	list-style-type: none;
	position: relative;
	height: 420px;
	width: 636px;
	overflow: hidden;
}
#chart ol li {
	text-indent: -9999em;
	width: 140px;
	position: absolute;
	bottom: 0;
	background-repeat: no-repeat;
	background-position: -140px 0;
	background-color: transparent;
	padding: 38px 0 0 0;
}
#green_bar {
	height: 150px;
	background-image: url('../images/green_bar_top.png');
	left: 80px;
}
#green_bar span {
	background: transparent url('../images/green_bar.png') no-repeat left bottom;
	display: block;
	height: 150px;
}
#yellow_bar {
	height: 200px;
	background-image: url('../images/yellow_bar_top.png');
	left: 260px;
}
#yellow_bar span {
	background: transparent url('../images/yellow_bar.png') no-repeat left bottom;
	display: block;
	height: 200px;
}
#red_bar {
	height: 100px;
	background-image: url('../images/red_bar_top.png');
	left: 440px;
}
#red_bar span {
	background: transparent url('../images/red_bar.png') no-repeat left bottom;
	display: block;
	height: 100px;
}</code></pre>
<h4>Step 3: Adding some jQuery animation</h4>
<p>At this point we have a fairly nice looking three dimensional graph using only CSS and some markup: now to add the animation! All we need to do is position the bars below the x-axis using jQuery, and then add the animation that will slide them in. It&#8217;s pretty simple, but looks pretty nice. It does have it&#8217;s drawbacks, as the height of the highest bar needs to be known so that the chart background image can be created. Any dynamic graphs that are created on-the-fly will be difficult to create, but for one-off static graphs, this is a neat little effect.</p>
<pre><code>$(function() {
  // hide the bars to begin with
	$('#chart ol li').each(function() {
		$(this).css({'bottom': '-' + $(this).height() + 'px'});
		$(this).css({'background-position': '0 0'});
	});
  // animate the bars position to show on the graph
	$('&lt;p&gt;<a href="#">Show_results</a>&lt;/p&gt;').click(function() {
		$('#chart ol li').each(function() {
			$(this)
			.css({'background-position': '-140px 0'})
			.animate({
				bottom: '0px'
			}, 500);
		});
		return false;
	}).appendTo('body');
});</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2009/08/20/css-bar-chart-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

