<?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>Elzo Valugi &#187; pan</title>
	<atom:link href="http://blog.valugi.ro/tag/pan/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.valugi.ro</link>
	<description>professional websurfing</description>
	<lastBuildDate>Sun, 25 Jul 2010 06:34:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Simulating a Pan Image jQuery plugin</title>
		<link>http://blog.valugi.ro/2009/07/31/simulating-a-pan-image-jquery-plugin/</link>
		<comments>http://blog.valugi.ro/2009/07/31/simulating-a-pan-image-jquery-plugin/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 11:16:04 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[pan]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=319</guid>
		<description><![CDATA[Fact: jQuery has plugins for everything. Fact: you don&#8217;t have to use plugins for everything. Working on a custom javaScript intensive CMS I get the task of displaying a big image inside a controlled environment. I could have used a plugin like MbImgNavigator or ImageZoom. I implemented both but I wasn&#8217;t particularly satisfied with neither. [...]]]></description>
			<content:encoded><![CDATA[<p>Fact: jQuery has plugins for everything.</p>
<p>Fact: you don&#8217;t have to use plugins for everything.</p>
<p>Working on a custom javaScript intensive CMS I get the task of displaying a big image inside a controlled environment. I could have used a plugin like <a href="http://pupunzi.wordpress.com/2009/01/20/mbimgnavigator/">MbImgNavigator</a> or <a href="http://www.visual-blast.com/source/jqzoom/">ImageZoom</a>. I implemented both but I wasn&#8217;t particularly satisfied with neither.</p>
<p>So I created my own simulation that is just a couple of lines without even the need for something complex.<br />
What it does:</p>
<ul>
<li>checking if the image is bigger than then the restrictive container</li>
<li>modifies a envelope container to allow movement only between the calculated permitted limits</li>
<li>activates the drag (jQueryUI) by globally or by axis if only one of the dimensions is overlapping the limits</li>
</ul>
<p>If the image is smaller that the limits nothing happens.<br />
<code class="javascript"><br />
	$(document).ready( function (){<br />
		var overflow_x = 0;<br />
		var overflow_y = 0;<br />
		var _image_x = $('#imageTest').width();<br />
		var _image_y = $('#imageTest').height();<br />
		if( _image_x > 300 ){<br />
			overflow_x = _image_x;<br />
		}<br />
		if( _image_y > 300 ){<br />
			overflow_y = _image_y;<br />
		}<br />
		if( overflow_x &#038;&#038; overflow_y ){<br />
			$('#bckContainerImg').css(<br />
				{<br />
					height: (overflow_y * 2 - 300),<br />
					width: ( overflow_x * 2 - 300 ),<br />
					'margin-top' : -( overflow_y - 300),<br />
					'margin-left': -( overflow_x - 300)<br />
				}<br />
			);<br />
			$("#bigImg img").draggable({containment: '#bckContainerImg'}).css({ cursor: 'all-scroll'});<br />
		} else{<br />
			if( overflow_x ){<br />
				$('#bckContainerImg').css({width: ( overflow_x*2 -300 ), 'margin-left': -(overflow_x - 300) });<br />
				$("#bigImg img").draggable({ axis: 'x', containment: '#bckContainerImg' }).css({ cursor: 'e-resize'});<br />
			}<br />
			if( overflow_y ){<br />
				$('#bckContainerImg').css({ height: (overflow_y * 2 - 300),  'margin-top': -(overflow_y - 300),});<br />
				$("#bigImg img").draggable({ axis: 'y', containment: '#bckContainerImg' }).css({ cursor: 'n-resize'});<br />
			}<br />
		}<br />
	});<br />
</code></p>
<p>You can see a <a href="http://dev.valugi.ro/jquery/pan-image/">full demo here</a>.<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2009/07/31/simulating-a-pan-image-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
