<?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>Steve Taylor &#187; jQuery</title>
	<atom:link href="http://sltaylor.co.uk/blog/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://sltaylor.co.uk</link>
	<description>Freelance WordPress developer in London - XHTML, CSS &#38; design</description>
	<lastBuildDate>Wed, 25 Apr 2012 20:43:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Fading in images sequentially in jQuery</title>
		<link>http://sltaylor.co.uk/blog/fading-in-images-sequentially-jquery/</link>
		<comments>http://sltaylor.co.uk/blog/fading-in-images-sequentially-jquery/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 16:23:18 +0000</pubDate>
		<dc:creator>Steve Taylor</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://sltaylor.co.uk/?p=474</guid>
		<description><![CDATA[This took me ages to figure out. I don&#8217;t know why. Anyway, I was creating a gallery of thumbnail images, and I wanted each image to fade in sequentially. The next image would start fading in before the previous one&#8217;s jQuery fadeIn had completed, so I couldn&#8217;t really use a callback. Of course, the solution [...]]]></description>
			<content:encoded><![CDATA[<p>This took me ages to figure out. I don&#8217;t know why. Anyway, I was creating a gallery of thumbnail images, and I wanted each image to fade in sequentially. The next image would start fading in before the previous one&#8217;s jQuery <code>fadeIn</code> had completed, so I couldn&#8217;t really use a callback.<br />
<span id="more-474"></span></p>
<p>Of course, the solution is a plain JavaScript <code>setTimeout</code>. The tricky bit was that for some reason this kind of code didn&#8217;t work:</p>
<pre name="code" class="javascript">thumbTimer = setTimeout( loadThumbs(), 70 );</pre>
<p>In the end I had to use this:</p>
<pre name="code" class="javascript">thumbTimer = setTimeout( function() { loadThumbs(); }, 70 );</pre>
<p>Grooooaaaaannn&#8230; Well, here&#8217;s the full function:</p>
<pre name="code" class="javascript">function loadThumbs() {
		var thumbTimer;
		// Initialize / increment counter
		if ( typeof loadThumbs.counter == 'undefined' ) {
			loadThumbs.counter = 0;
		} else {
			loadThumbs.counter++;
		}
		if ( loadThumbs.counter &lt; numThumbs ) {
			// Load and fade in a thumbnail
			$( "#thumbnails" ).append( '&lt;div class="tn" id="tn-' + loadThumbs.counter + '"&gt;&lt;a href="[????]" title="Click to see full size"&gt;&lt;div class="thumbnail" style="display:none;width:86px;height:86px;overflow:hidden;background:url([????]) no-repeat ' + ( 0 - ( loadThumbs.counter * 86 ) ) + 'px 0px" /&gt;&lt;/a&gt;&lt;/div&gt;' );
			$( "#tn-" + loadThumbs.counter + " div.thumbnail" ).fadeIn( 500 );
			thumbTimer = setTimeout( function() { loadThumbs(); }, 70 );
		} else {
			// All thumbs loaded, add "glow" event
			$( ".tn a" ).mouseover( function() {
				$( this ).children( ".thumbnail" ).stop( true, true ).animate({
					opacity: 0.6
				}, 200, "swing", function() {
					$( this ).animate({
						opacity: 1
					}, 400 );
				});
			});
		}
	}
}</pre>
<p>A few words of explanation:</p>
<ul>
<li>This code isn&#8217;t &#8220;self-contained&#8221;! You can&#8217;t just drop it somewhere and have stuff happen. I&#8217;m posting it to convey as specific bit of syntax (described above), and give it a bit of context. You&#8217;ll need a bunch of other HTML and CSS to get this going, and it should be obvious what&#8217;s needed. If it&#8217;s not, please <a href="http://www.google.co.uk/search?q=jquery+image+gallery">Google for a complete image gallery solution</a>.</li>
<li>You&#8217;ll need to call <code>loadThumbs</code> once the page is loaded, of course.</li>
<li>You&#8217;ll also need to set <code>numThumbs</code> inline on the page somewhere. I&#8217;m working this out server-side and using PHP to write the JS. You could try something else if you want&#8230;</li>
<li>The code is designed to work with a pre-existing <code>div</code> with <code>thumbnails</code> as an ID on the page.</li>
<li>Replace instances of <code>[????]</code> with your URL structure to full-size images and thumbnails.</li>
<li>For various reasons, I&#8217;m working with one big image which has all the thumbnails in a strip. Each thumbnails is 86 x 86 pixels, and each thumbnail&#8217;s <code>div</code> includes it as a background image, its position shifted to show the right bit.</li>
<li>Tweak the <code>fadeIn</code> and <code>setTimeout</code> millisecond settings as necessary!</li>
<li>I&#8217;ve include a nice &#8220;glow&#8221; effect as a bonus. :)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sltaylor.co.uk/blog/fading-in-images-sequentially-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery image hover effect</title>
		<link>http://sltaylor.co.uk/blog/jquery-image-hover-effect/</link>
		<comments>http://sltaylor.co.uk/blog/jquery-image-hover-effect/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 23:38:52 +0000</pubDate>
		<dc:creator>Steve Taylor</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://sltaylor.co.uk/?p=424</guid>
		<description><![CDATA[I&#8217;ve just been trying to replicate a certain effect I saw in Flash image gallery with jQuery. When you hover over a thumbnail, it &#8220;glows&#8221; a little&#8212;not an &#8220;outer glow&#8221;, but the whole image just becomes brighter for a moment then the brightness fades back. A very simple effect, and in the end doing it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just been trying to replicate a certain effect I saw in Flash image gallery with jQuery. When you hover over a thumbnail, it &#8220;glows&#8221; a little&#8212;not an &#8220;outer glow&#8221;, but the whole image just becomes brighter for a moment then the brightness fades back.</p>
<p>A very simple effect, and in the end doing it in jQuery was pretty simple, but I thought I&#8217;d document it. My technique has one caveat: it relies on the background being white, because it basically achieves the effect by temporarily reducing the opacity of the thumbnail image. If you have a background colour different from the colour you want the image to &#8220;glow&#8221; with, I&#8217;m sure there&#8217;s a way. You could probably use positioning to put a blank white image <em>behind</em> the thumbnail, and use this technique as-is.</p>
<p><span id="more-424"></span></p>
<p>Anyway, here&#8217;s some typical HTML:</p>
<pre name="code" class="html">&lt;div class="thumbnail"&gt;
	&lt;a href="fullsize.html"&gt;&lt;img src="thumb.jpg" alt="thumbnail" /&gt;&lt;/a&gt;
&lt;/div&gt;</pre>
<p>And here&#8217;s the important stuff, the jQuery:</p>
<pre name="code" class="javascript">jQuery( document ).ready( function($) {
	$( ".thumbnail a" ).mouseover( function() {
		$( this ).children( "img" ).stop( true, true ).animate({
			opacity: 0.6
		}, 200, "swing", function() {
			$( this ).animate({
				opacity: 1
			}, 400 );
		});
	});
});</pre>
<p>The <code>stop()</code> function in line 3 clears any queued-up effects when the mouse goes over. This stops things looking weird when someone goes crazy fast with their mouse.</p>
<p>The first <code>opacity</code> setting is for the &#8220;glow&#8221; to come through from the white background. If you want a brighter glow, make this value lower. The <code>200</code> just after is the number of milliseconds it&#8217;ll take for it to get to that opacity.</p>
<p>Then there&#8217;s the callback function which restores the original opacity. Again, the <code>400</code> is the timing value. Adjust this and the <code>200</code> to change the &#8220;rhythm&#8221; of the glow effect.</p>
<p>Have fun with it!</p>
]]></content:encoded>
			<wfw:commentRss>http://sltaylor.co.uk/blog/jquery-image-hover-effect/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding scripts to the WordPress login or registration form</title>
		<link>http://sltaylor.co.uk/blog/adding-scripts-wordpress-login-registration-form/</link>
		<comments>http://sltaylor.co.uk/blog/adding-scripts-wordpress-login-registration-form/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 22:24:49 +0000</pubDate>
		<dc:creator>Steve Taylor</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sltaylor.co.uk/?p=295</guid>
		<description><![CDATA[Most WP developers know by now that the right way to add script libraries from a plugin or theme is to use the wp_enqueue_script function. It makes sure scripts aren&#8217;t loaded more than once, and so on. However, I just had some problems getting some jQuery to run on the login / registration form. I [...]]]></description>
			<content:encoded><![CDATA[<p>Most WP developers know by now that the right way to add script libraries from a plugin or theme is to use the <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script"><code>wp_enqueue_script</code></a> function. It makes sure scripts aren&#8217;t loaded more than once, and so on.</p>
<p>However, I just had some problems getting some jQuery to run on the login / registration form. I used <code>wp_enqueue_script</code> like a good WP developer but&#8230; no go. Where&#8217;s my jQuery?</p>
<p>It seems the answer lies in the fact that after scripts are enqueued in a normal WP page, they get spit out by something inside the call to <code>wp_head()</code>. I guess you could add <code>wp_head()</code> to the login header, but who wants all those redundant plugin scripts and styles that (presumably) aren&#8217;t even meant to be there.</p>
<p>After a bit of digging around it seems that the solution is the <code>wp_print_scripts()</code> function. So, to get jQuery working on the login form, put these lines in the code you hook onto <code>login_head</code>:</p>
<pre name="code" class="php">wp_enqueue_script( 'jquery' );
wp_print_scripts();</pre>
]]></content:encoded>
			<wfw:commentRss>http://sltaylor.co.uk/blog/adding-scripts-wordpress-login-registration-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery hover drop-down menus and the setTimeout issue</title>
		<link>http://sltaylor.co.uk/blog/jquery-hover-drop-down-menu-settimeout/</link>
		<comments>http://sltaylor.co.uk/blog/jquery-hover-drop-down-menu-settimeout/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 18:25:35 +0000</pubDate>
		<dc:creator>Steve Taylor</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://sltaylor.co.uk/?p=161</guid>
		<description><![CDATA[You know those days when you kind of know there&#8217;s plugins and whatnot aplenty to do something? But you&#8217;re feeling stubborn, and you&#8217;d rather re-invent the wheel? Today has been like that. It&#8217;s not just being stubborn, though. Sometimes you want to re-invent the wheel so you know how to make better wheels yourself. In [...]]]></description>
			<content:encoded><![CDATA[<p>You know those days when you kind of know there&#8217;s plugins and whatnot aplenty to do something? But you&#8217;re feeling stubborn, and you&#8217;d rather re-invent the wheel? Today has been like that.</p>
<p>It&#8217;s not just being stubborn, though. Sometimes you want to re-invent the wheel so you know how to make better wheels yourself. In coding, you have to strike a balance between getting stuff done quickly and efficiently by relying on what&#8217;s already been done, and actually progressing your own skills.</p>
<p>Anyway, today I solved something that had been bugging me for a while: creating slick drop-down menus. I know CSS-based drop-downs, and they&#8217;re a good thing. But having got into <a href="http://docs.jquery.com/Main_Page">jQuery</a> recently, I wanted to get them right with scripting.</p>
<p><span id="more-161"></span></p>
<p>The main trick I&#8217;d missed was how to make sure that if the cursor passes quickly over a menu item, the &#8220;show menu&#8221; bit doesn&#8217;t get triggered&#8212;preventing shoddy, jittery menus popping up all over as you reach for the page scroller or something.</p>
<p>Well, after a few hours&#8217; wrangling, here&#8217;s the code:</p>
<pre name="code" class="js">jQuery( document ).ready( function($) {
	var navTimers = [];
	$( "#nav-main ul.nav &gt; li" ).hover(
		function () {
			var id = jQuery.data( this );
			var $this = $( this );
			navTimers[id] = setTimeout( function() {
				$this.children( 'ul' ).fadeIn( 300 );
				navTimers[id] = "";
			}, 300 );
		},
		function () {
			var id = jQuery.data( this );
			if ( navTimers[id] != "" ) {
				clearTimeout( navTimers[id] );
			} else {
				$( this ).children( "ul" ).fadeOut( 200 );
			}
		}
	);
});</pre>
<p>A few words of explanation:</p>
<p>The <code>navTimers</code> array is crucial. The key to all this is storing a separate <a href="https://developer.mozilla.org/en/window.setTimeout"><code>setTimeout()</code></a> timer reference for each menu element that the cursor goes over.</p>
<p>OK, so <code>#nav-main ul.nav > li</code> selects the immediate children of my main nav menu list, and then I set up the <a href="http://docs.jquery.com/Events/hover">hover</a> functions.</p>
<p>The first line in each hover function uses the jQuery <a href="http://docs.jquery.com/Internals/jQuery.data#elem"><code>data()</code></a> function, which returns a unique ID for the current element (just an integer, which seems to be related to the order of the elements). We use that as our key for the <code>navTimers</code> array.</p>
<p>In the &#8220;over&#8221; function, we create a reference to the jQuery object for the current element, so we can pass it through to the function inside <code>setTimeout()</code>. Then when initialize the <code>setTimeout()</code> itself, the function inside it doing two things:</p>
<ol>
<li>Triggers the jQuery <code>fadeIn()</code> effect.</li>
<li>Clears its own reference in <code>navTimers</code>. (Actually I&#8217;m not sure if this is cleared automatically after the timer expires&#8212;I did this just to be safe.)</li>
</ol>
<p>That 300 at the end of the <code>setTimeout()</code> is the number of milliseconds it&#8217;ll wait before triggering the <code>fadeIn()</code>. The 300 <em>inside</em> the <code>fadeIn()</code> is the number of milliseconds jQuery will take to do the fade.</p>
<p>The &#8220;out&#8221; function checks if there&#8217;s a timer set for the current element. If there is, it just clears it. This is the eventuality where the cursor has gone over and then out of the element&#8217;s space within our set limit (300 ms). If there isn&#8217;t a timer, i.e. the timer&#8217;s expired and the drop-down&#8217;s been shown, then it hides the drop-down.</p>
<p>Whew! Do let me know if you spot any issues, or ways of doing things better.</p>
<p>Oh, if you&#8217;re here looking for a ready-made drop-down menu solution, including markup and CSS&#8230; apologies, but this post is to help out other who are being stubborn and a re-inventing the wheel ;-). But really, if you can&#8217;t find a good plugin (I&#8217;m working within the WordPress world here by the way), the markup and CSS are the easy bits. Hopefully the above helps out with the tricky JavaScript.</p>
<p><strong class="alert">UPDATE 29/7/11:</strong> It seems that as of jQuery 1.4, <code>jQuery.data( elem )</code> no longer returns a unique ID for the element. I&#8217;ve not worked with the above code for a while, but I imagine it&#8217;s broken for 1.4. The new way that the <a href="http://api.jquery.com/jQuery.data/"><code>data</code> method</a> works is to store key / value data associated with an element. The above code might be rewritten for 1.4 to store that timer objects in each element using this method. Please <a href="/contact/">contact me</a> if you come up with a new version!</p>
]]></content:encoded>
			<wfw:commentRss>http://sltaylor.co.uk/blog/jquery-hover-drop-down-menu-settimeout/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  sltaylor.co.uk/blog/category/jquery/feed/ ) in 0.26237 seconds, on May 17th, 2012 at 1:23 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 17th, 2012 at 2:23 pm UTC -->
