<?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>Bri Manning&#039;s Blog &#187; jQuery</title>
	<atom:link href="http://brimanning.com/blog/category/javascript/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://brimanning.com/blog</link>
	<description>A Developnerd&#039;s Take on Being Awesome</description>
	<lastBuildDate>Thu, 19 Jan 2012 15:15:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Yes, I Position My Background Image with jQuery</title>
		<link>http://brimanning.com/blog/yes-i-position-my-background-image-with-jquery</link>
		<comments>http://brimanning.com/blog/yes-i-position-my-background-image-with-jquery#comments</comments>
		<pubDate>Sun, 25 Oct 2009 17:50:26 +0000</pubDate>
		<dc:creator>Brian Manning</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://staging.brimanning.com/blog/?p=15</guid>
		<description><![CDATA[How do I position the "hook" in my background?]]></description>
			<content:encoded><![CDATA[<p>
So, notice that green hook on the left there?  How much of it can you see?  And what happens if you resize the window?
</p>
<p>
Now, if you&#8217;re a front-end guy, you know that a background image cannot extend outside of an element.  But what if you want to position that background relative to the position of an element, but outside of that element?  I had the same problem&#8230;
</p>
<p>
Now, I&#8217;m a huge fan of <a href="http://jquery.com" title="Simple JavaScript Framework">jQuery</a>, so I decided to go that route.  Here&#8217;s what I did:
</p>
<pre><code>$('body')
    .css('background-position',
        $('#container').offset().left - 320 + 'px ' +
        $('#container').offset().top + 'px');
</code></pre>
<p>
What does that do?  jQuery finds the body element: <code>$('body')</code> and it sets the background position using <code>.css('background-position', value)</code>.  But, we need to get the position of my #container element, so we do that using <code>$('#container').offset().left</code> (with a 320px nudge) and <code>$('#container').offset().top</code>.
</p>
<p>
Put that in jQuery&#8217;s <code>$(document).ready(function()</code> and huzzah!
</p>
<p>
Well, what happens if you resize?  Uh-oh, one more thing to do.  I promise it won&#8217;t be hard though.  Let&#8217;s just bring jQuery to the rescue again using <code>$(window).bind('resize', function()</code>.  And, to keep up with DRY coding principles, we&#8217;ll pull it out into an <code>alignBG()</code> function, giving us:
</p>
<pre><code>function alignBG(){
    $('body')
        .css('background-position',
            $('#container').offset().left - 320 + 'px ' +
            $('#container').offset().top + 'px');
}

$(document).ready(function(){
    alignBG();

    $(window).bind('resize', function() {
        alignBG();
    });
}
</code></pre>
<p>
And there you have it!  That&#8217;s how you can position a background image based on a different element&#8217;s location in jQuery making sure that it&#8217;s in the right place on a resize.</p>
]]></content:encoded>
			<wfw:commentRss>http://brimanning.com/blog/yes-i-position-my-background-image-with-jquery/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

