<?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>CSSquirrel &#187; jquery</title>
	<atom:link href="http://cssquirrel.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://cssquirrel.com/blog</link>
	<description>opinions and news on web design</description>
	<lastBuildDate>Fri, 18 May 2012 16:26:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Elsewhere: William Flake&#8217;s &#8220;Of Squirrels and Men&#8221;</title>
		<link>http://cssquirrel.com/blog/2009/12/08/elsewhere-michael-flakes-of-squirrels-and-men/</link>
		<comments>http://cssquirrel.com/blog/2009/12/08/elsewhere-michael-flakes-of-squirrels-and-men/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 21:25:32 +0000</pubDate>
		<dc:creator>Kyle Weems</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[elsewhere]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[parallax]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[william flake]]></category>

		<guid isPermaLink="false">http://www.cssquirrel.com/?p=541</guid>
		<description><![CDATA[Last Friday in response to a question by Tyrun I posted a little micro-tutorial about how I achieve the parallax scrolling header for the site, walking through the steps on setting up images, CSS, HTML and JavaScript (in particular, I use jQuery). I also learned a thing or two about how annoying WordPress can be [...]]]></description>
			<content:encoded><![CDATA[<p>Last Friday in response to a question by <a title="Link to Tyrun on Twitter" href="http://www.twitter.com/Tyrun" target="_blank">Tyrun</a> I posted a little micro-tutorial about how I achieve the <a title="Link to The Parallax Header: How I Do It" href="/2009/12/04/the-parallax-header-how-i-do-it/">parallax scrolling header</a> for the site, walking through the steps on setting up images, CSS, HTML and JavaScript (in particular, I use <a title="Link to jQuery" href="http://jquery.com/" target="_blank">jQuery</a>). I also learned a thing or two about how annoying WordPress can be with code snippets in posts (Use <strong>&lt;pre&gt;</strong>. Really. I don&#8217;t know why I didn&#8217;t.)</p>
<p>Everything in the tutorial is exactly as it was on my site at the time of writing. However, this is no longer the case. Over the weekend I got a tweet from <a title="Link to William Flake's Unfinished Thoughts" href="http://williamflake.com/" target="_blank">William Flake</a> indicating a modification he made to the code to prevent a &#8220;jump&#8221; that occurred when you first moved the mouse into the header. I liked his alterations so much that I&#8217;ve made use of them in my code.</p>
<p>This week William wrote about his code alterations over at his site <a title="Link to William Flake's Unfinished Thoughts" href="http://williamflake.com/" target="_blank">Unfinished Thoughts</a> in a post entitled <a title="Link to Of Squirrels and Men by William Flake" href="http://williamflake.com/blog/2009/12/6/Of_Squirrels_and_Men/" target="_blank">Of Squirrels and Men</a>. If you enjoyed my parallax code, please take a look at what changes he made. They&#8217;re definitely worth a gander.</p>
]]></content:encoded>
			<wfw:commentRss>http://cssquirrel.com/blog/2009/12/08/elsewhere-michael-flakes-of-squirrels-and-men/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Parallax Header: How I Do It</title>
		<link>http://cssquirrel.com/blog/2009/12/04/the-parallax-header-how-i-do-it/</link>
		<comments>http://cssquirrel.com/blog/2009/12/04/the-parallax-header-how-i-do-it/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 21:20:44 +0000</pubDate>
		<dc:creator>Kyle Weems</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[cool]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[parallax]]></category>

		<guid isPermaLink="false">http://www.cssquirrel.com/?p=515</guid>
		<description><![CDATA[This morning I was asked by Tyrun on Twitter (sorry, I couldn&#8217;t find your actual name, sir) about something that I&#8217;ve been asked a few times: I LOVE your header background, how on earth did you do that? The very short answer is: with JavaScript and CSS. Of course, that&#8217;s not a very satisfying response, [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I was asked by <a title="Link to Tyrun on Twitter" href="http://www.twitter.com/Tyrun" target="_blank">Tyrun</a> on Twitter (sorry, I couldn&#8217;t find your actual name, sir) <a title="Link to a tweet by Tyrun" href="http://twitter.com/Tyrun/statuses/6343767199" target="_blank">about something</a> that I&#8217;ve been asked a few times: <q>I LOVE your header background, how on earth did you do that?</q></p>
<p>The very short answer is: with JavaScript and CSS.</p>
<p>Of course, that&#8217;s not a very satisfying response, so I&#8217;ll go ahead and expound a bit more. I did it in three steps. First, creating the right group of images. Secondly, with some simple CSS and HTML. Lastly, with a surprisingly short JS script.</p>
<h4>Step 1: The Images</h4>
<p>The first step for parallax scrolling, in any application, is having multiple layers of images to scroll at different speeds, with each layer representing another part of the passing landscape. In the case of this site, I&#8217;ve got four: clouds, mountains, hills, and forest. By themselves, neither layer looks terribly interesting.</p>
<h5>Layer 1: Clouds</h5>
<p><img style="border: 2px solid black; background-color: #63b3d9; width: 95%;" src="/wp-content/themes/cssquirrel/version2/images/clouds.png" alt="clouds" /></p>
<h5>Layer 2: Mountains</h5>
<p><img style="border: 2px solid black; width: 95%;" src="/wp-content/themes/cssquirrel/version2/images/mountains.png" alt="mountains" /></p>
<h5>Layer 3: Hills</h5>
<p><img style="border: 2px solid black; width: 95%;" src="/wp-content/themes/cssquirrel/version2/images/hills.png" alt="hills" /></p>
<h5>Layer 4: Forest</h5>
<p><img style="border: 2px solid black; width: 95%;" src="/wp-content/themes/cssquirrel/version2/images/forest.png" alt="forest" /></p>
<p>They&#8217;ll have to be stacked over each other, so in order to be seen through one another they need to have transparency. This is why I used PNGs (although depending on the type of art you use, GIFs are fine).</p>
<h4>Step 2: The CSS and HTML</h4>
<p>Next, the images will have to be stacked over each other. I made four empty divs which I put in the header/branding div as follows:</p>
<pre class="code-ex">&lt;div id="cloudLayer" &gt; &lt;/div&gt;
&lt;div id="mountainLayer" &gt; &lt;/div&gt;
&lt;div id="hillLayer" &gt; &lt;/div&gt;
&lt;div id="forestLayer"&gt; &lt;/div&gt;</pre>
<p>Although I&#8217;m not normally a fan of non-semantic divs, for this special effect I need something to hang the imagery upon. These four divs will be what we need for the CSS:</p>
<pre class="code-ex">
<span>div#cloudLayer, div#mountainLayer, div#hillLayer, div#forestLayer</span> {
<span> height</span><span>:</span><span>200px</span><span>;</span>
<span> position</span><span>:</span><span>absolute</span><span>;</span>
<span> text-indent</span><span>:</span><span>-9999em</span><span>;</span>
<span> width</span><span>:</span><span>100%</span><span>;</span>
}

div#cloudLayer {
background:transparent url(images/clouds.png) repeat-x scroll left top;
opacity:0.6;
}

div#mountainLayer {
background:transparent url(images/mountains.png) repeat-x scroll left top;
}

div#hillLayer {
background:transparent url(images/hills.png) repeat-x scroll left top;
}

div#forestLayer {
background:transparent url(images/forest.png) repeat-x scroll left top;
}
</pre>
<p>So each div is set at the same height, as wide as the parent element (the header), and absolutely positioned so they all overlap. Each background image is set appropriately to repeat horizontally along the layer it is within. If nothing further was done, this would be a complicated way to create a repeating landscape background. Only one small bit is left to make it scroll.</p>
<h4>Step 3: The JavaScript (with jQuery!)</h4>
<p>I love <a title="Link to jQuery" href="http://jquery.com/" target="_blank">jQuery</a>. It&#8217;s a convenient, compact JS library that makes cross-browser coding easy and compact. You could probably do this script without it, but by necessity it&#8217;d be a lot larger. Here&#8217;s the part of my script that controls the scrolling:</p>
<pre class="code-ex">$('#branding').mousemove(function(e) {
mouseX = e.clientX;
$('#cloudLayer').css('background-position', Math.floor(mouseX / 4) + 'px 0');
$('#mountainLayer').css('background-position', Math.floor(mouseX / 3) + 'px 0');
$('#hillLayer').css('background-position', Math.floor(mouseX / 2) + 'px 0');
$('#forestLayer').css('background-position', mouseX + 'px 0');
});</pre>
<p>I want the scrolling to only occur when the mouse is over the header, which is a div I call <strong>branding</strong>. So I&#8217;ve bound the <strong>.mousemove() </strong>event handling function to that div. I get the x-coordinate of the mouse when that even fires (anytime the mouse moves) and then adjust the background image positioning on the layer divs accordingly.</p>
<p>If I moved each layer&#8217;s background image by the same amount, the image would scroll all at once, and there&#8217;d be no parallax effect. Therefore, I instead divide the x-coordinate by a different amount for three of the four layers, moving each background image an increasingly smaller amount for the &#8220;far&#8221; layers.</p>
<p>The finished result is visible in the header above!</p>
<p>As always, if you have any comments or questions, feel free to share.</p>
]]></content:encoded>
			<wfw:commentRss>http://cssquirrel.com/blog/2009/12/04/the-parallax-header-how-i-do-it/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Correcting Overlay Issues with jQuery Lightbox and Fixed Body Width</title>
		<link>http://cssquirrel.com/blog/2009/04/24/correcting-overlay-issues-with-jquery-lightbox-and-fixed-body-width/</link>
		<comments>http://cssquirrel.com/blog/2009/04/24/correcting-overlay-issues-with-jquery-lightbox-and-fixed-body-width/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 19:33:19 +0000</pubDate>
		<dc:creator>Kyle Weems</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[lightbox]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.cssquirrel.com/?p=240</guid>
		<description><![CDATA[This is a quicky. As plenty know, Lightbox is a convenient and quick solution to providing a slightly glossy gallery effect for a page of photos or artwork. I personally prefer jQuery Lightbox, mainly because I&#8217;m a jQuery addict, but there is a slight issue with it being used in sites that have a fixed [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quicky.</p>
<p>As plenty know, Lightbox is a convenient and quick solution to providing a slightly glossy gallery effect for a page of photos or artwork. I personally prefer <a title="Link to jQuery Lightbox" href="http://leandrovieira.com/projects/jquery/lightbox/" target="_blank">jQuery Lightbox</a>, mainly because I&#8217;m a <a title="Link to jQuery" href="http://jquery.com" target="_blank">jQuery</a> addict, but there is a slight issue with it being used in sites that have a fixed width on the body element (which I try not to do myself, since who knows what the end-users monitor is going to be like, but for client sites  I don&#8217;t always have that freedom).</p>
<p>The issue is illustrated in <a title="jQuery Lightbox and Fixed Body Width Example #1" href="http://www.cssquirrel.com/testcases/jqlbfix/example1.htm" target="_blank">this example here</a>: the dark-background overlay that appears to cover the page doesn&#8217;t go past the margin of the body, leaving distracting bright gutters that ruin the desired effect.</p>
<p>In cases where you need (for whatever reason) a fixed body width, the solution here for jQuery Lightbox is fairly straightforward, but involves a wee bit of modification to the jquery.lightbox.js file&#8217;s code.</p>
<p>Inside the file, find the _set_interface() function and look for this segment of code:</p>
<pre>            $('#jquery-overlay').css({
                backgroundColor:    settings.overlayBgColor,
                opacity:            settings.overlayOpacity,
                width:                arrPageSizes[0],
                height:                arrPageSizes[1]
            }).fadeIn();</pre>
<p>We need to change it to the following:</p>
<pre>            $('#jquery-overlay').css({
                backgroundColor: settings.overlayBgColor,
                opacity: settings.overlayOpacity,
                width: <strong>$(window).width()</strong>,
                height: arrPageSizes[1],
                left:<strong> -(($(window).width() - $('body').width()) / 2)</strong>
            }).fadeIn();</pre>
<p>Why is this? Let&#8217;s focus on the changes.</p>
<p>The width has been changed to $(window).width() so it actually gets the width of the browser window, and not just the body element, across all browsers (the provided value only provides the body element width in IE, Webkit, and Opera). Without this, the overlay won&#8217;t get wide enough to cover everything up.</p>
<p>The new value, left, gives the css style that will position the overleft to the left side of the screen by subtracting the difference of the browser&#8217;s width and the body&#8217;s width. This will allow it to work for all browser sizes.</p>
<p>Lastly, we need to put overflow: visible on the body element in our CSS. With this, we can see the overlay when it goes outside the body&#8217;s borders.</p>
<p>With these tiny changes in effect, check out the<a title="jQuery Lightbox and Fixed Body Width Example #2" href="http://www.cssquirrel.com/testcases/jqlbfix/example2.htm" target="_blank"> new result here</a>. Much better, isn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://cssquirrel.com/blog/2009/04/24/correcting-overlay-issues-with-jquery-lightbox-and-fixed-body-width/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Bug or Stupidity?: jQuery, Imagemaps, and Dynamically Inserting Area Tags</title>
		<link>http://cssquirrel.com/blog/2008/11/12/bug-or-stupidity-jquery-imagemaps-and-dynamically-inserting-area-tags/</link>
		<comments>http://cssquirrel.com/blog/2008/11/12/bug-or-stupidity-jquery-imagemaps-and-dynamically-inserting-area-tags/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 19:09:06 +0000</pubDate>
		<dc:creator>Kyle Weems</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.cssquirrel.com/?p=155</guid>
		<description><![CDATA[I&#8217;ve run across something that is not making any sense to me. The situation: I&#8217;ve got an empty imagemap that I want to dynamically enter area tags into with jQuery. I&#8217;ve been trying to insert them using .append() or even .html() and every time I attempt to do so nothing occurs. I can insert text [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve run across something that is not making any sense to me.</p>
<p>The situation: I&#8217;ve got an empty imagemap that I want to dynamically enter area tags into with jQuery. I&#8217;ve been trying to insert them using <strong>.append()</strong> or even <strong>.html()</strong> and every time I attempt to do so nothing occurs. I can insert text or other tags, but no actual area tags.</p>
<p>Now, if I go oldschool and use <strong>document.getElementById(insertnamehere).innerHTML = &#8220;inserttagshere&#8221;</strong> that works. But every variation I can think of to use jQuery methods to add an area tag fails.</p>
<p>Can anyone think of anything obvious that I&#8217;m missing here?</p>
]]></content:encoded>
			<wfw:commentRss>http://cssquirrel.com/blog/2008/11/12/bug-or-stupidity-jquery-imagemaps-and-dynamically-inserting-area-tags/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery, JSON and IE &#8211; Getting Incorrect Array Length</title>
		<link>http://cssquirrel.com/blog/2008/10/14/jquery-json-and-ie-getting-incorrect-array-length/</link>
		<comments>http://cssquirrel.com/blog/2008/10/14/jquery-json-and-ie-getting-incorrect-array-length/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 20:24:58 +0000</pubDate>
		<dc:creator>Kyle Weems</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.cssquirrel.com/?p=106</guid>
		<description><![CDATA[Has anyone had the following problem? When loading a JSON array (through something like $.getJSON), Internet Explorer will sometimes report the length of the array being one higher than other browsers, with the extra element in the array being blank. I don&#8217;t know if this is a problem in other libraries, but I suspect it [...]]]></description>
			<content:encoded><![CDATA[<p>Has anyone had the following problem? When loading a <a title="Link to JSON.org" href="http://www.json.org/" target="_self">JSON</a> array (through something like <a title="Link to jQuery documentation on jQuery.getJSON" href="http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback" target="_blank">$.getJSON</a>), Internet Explorer will sometimes report the length of the array being one higher than other browsers, with the extra element in the array being blank.</p>
<p>I don&#8217;t know if this is a problem in other libraries, but I suspect it is. But I do know that it&#8217;s happened to me when using jQuery&#8217;s Ajax functions.</p>
<p>Why is this occurring?</p>
<p>I was tormenting myself with this same question on a client project, and discovered that although a bit of browser quirkiness was involved, it was actually an error on my part.</p>
<p>I hate it when it&#8217;s me. ;)</p>
<p><span id="more-106"></span></p>
<p>As it turns out, I had an extra trailing comma at the end of the last element in my array. For example, in the following array:</p>
<p><strong>{&#8220;gamesImDroolingFor&#8221;:[{"developer":"Blizzard","title:"Diablo III"},{"developer":"Square Enix","title":"Final Fantasy XIII"}<span style="color: #ff0000;">,</span>]}</strong></p>
<p>You&#8217;ll notice that there&#8217;s a comma after the last game&#8217;s bracket (which has been turned red for emphasis).</p>
<p>Firefox will ignore that comma, since clearly there&#8217;s no new object after it. Internet Explorer, the special child of the web, isn&#8217;t quite so bright, so it adds an extra, blank element to the array it creates.</p>
<p>Go IE.</p>
<p>The solution is easy, of course. Remove the unneeded comma.</p>
<p>I hope this helps prevent other developers from driving themselves batty trying to figure out what&#8217;s going wrong with their own arrays.</p>
]]></content:encoded>
			<wfw:commentRss>http://cssquirrel.com/blog/2008/10/14/jquery-json-and-ie-getting-incorrect-array-length/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

