<?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>Tech Mug &#187; trail</title>
	<atom:link href="http://www.techmug.com/tag/trail/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techmug.com</link>
	<description></description>
	<lastBuildDate>Tue, 31 Jan 2012 12:15:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>jMouse Follower</title>
		<link>http://www.techmug.com/jmouse-follower/</link>
		<comments>http://www.techmug.com/jmouse-follower/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 19:33:14 +0000</pubDate>
		<dc:creator>Fraz Ahmed</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[follow]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[swf]]></category>
		<category><![CDATA[trail]]></category>

		<guid isPermaLink="false">http://www.techmug.com/?p=28</guid>
		<description><![CDATA[What is Mouse Follower?

Mouse Follower or Cursor Trail is typically an image or set of images which follows the cursor in your browser screen.]]></description>
			<content:encoded><![CDATA[<h2>What is Mouse Follower?</h2>
<p>Mouse Follower or Cursor Trail is typically an image or set of images which follows the cursor in your browser screen.</p>
<h2><strong>Demo and Download</strong></h2>
<p>To understand more clearly visit <a title="jMouse Follower Demo" href="http://www.techmug.com/demo/mouse-follower/" target="_blank">demo</a>. Alternatively you may also download the files from <a title="Download jMouse Follower" href="http://www.techmug.com/demo/mouse-follower/mouse-follower.zip" target="_blank">here</a>.</p>
<h2><strong>Problem</strong></h2>
<p>Today I was asked to enhance the existing mouse trail feature of a website. They were using 3 or 4 PNG images to make the mouse trail. But the problem was that images were inline. While our client wanted some more advanced animation with mouse trail/follower. And that animation was not possible without using flash animation in it.</p>
<p>From the above its clear that we were need to have a DIV in the script where all of the Flash embedded code may be inserted. I searched for many scripts but the problem was that they were doing well with IE but for Firefox answer was NO.</p>
<p><span id="more-28"></span></p>
<h2><strong>Things to do</strong></h2>
<p>Eventually I had to play with code. And surely my first choice for Javascript is always jQuery. Basically the concept was so simple, to achieve Mouse Follower effect we need to do following:</p>
<ol>
<li>Create a DIV for Flash Object (You may also use image in this DIV).</li>
<li>Find X and Y co-ordinates of cursor&#8217;s current position.</li>
<li>Change DIV position according to X and Y position of Cursor.</li>
</ol>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7217075623453662";
google_ad_slot = "2820701010";
google_ad_width = 336;
google_ad_height = 280;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<center><font-size="9px">Advertisement</font></center></p>
<h2><strong>How it works?</strong></h2>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
$(document).ready(function(){
   $(&quot;*&quot;).mousemove(function(e){
	  $(&quot;#follower&quot;).css({'position' : 'absolute', 'margin-left' : e.pageX+10, 'margin-top' : e.pageY+10, 'display' : 'block', 'z-index' : '999'});
   });
})
// ]]&gt;&lt;/script&gt;
</pre>
<p><strong>Explanation</strong></p>
<ol>
<li>In the above code first we define use <em>document.ready()</em> it simply call the underneath function on the load of page.</li>
<li><em>$(&#8220;*&#8221;).mousemove(function(e){</em>&#8230; &#8211; this line reads that call the function whenever mouse move on any element of the page. <em>mousemove</em> is a jQuey event. Click <a title="jQuery Events" href="http://docs.jquery.com/Events" target="_blank">here</a> to learn more jQuery events.</li>
<li><em>$(&#8220;#follower&#8221;).css({</em>&#8230; &#8211; this line looks for an element which ID is &#8220;follower&#8221;. This is our Flash Object DIV. In this line we change the CSS style of our DIV. jQuery has made it much easy for us to change the CSS style of any element on the move.</li>
<li>We get X and Y co-ordinates by calling <em>page.X</em> and <em>page.Y</em> builtin functions of jQuery.</li>
<li>We used <em>margin-left</em> and <em>margin-top</em> to style our DIV. Values of both margins are set equivalent of <em>page.X</em> and <em>page.Y</em></li>
<li>So, every time when mouse moves on the page<em>, </em>our DIV changes its position itself. And this all is happening because we have defined the <em>position</em> of our DIV to <em>absolute. </em>So, DIV is free to move anywhere on the page.</li>
<li>We used <em>+10</em> with <em>page.X</em> and <em>page.Y</em> its just because we wanted to move our object a little far from the cursor.</li>
<li>Our DIV has a Flash Object. And we have made this flash animation a transparent one. So, it will not hide any element on the page. Code for our DIV is below:</li>
</ol>
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;follower&quot;&gt;
 &lt;object id=&quot;followers&quot; classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot; width=&quot;250&quot; height=&quot;150&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot;&gt;
 &lt;param name=&quot;name&quot; value=&quot;follower&quot; /&gt;
 &lt;param name=&quot;align&quot; value=&quot;middle&quot; /&gt;
 &lt;param name=&quot;allowScriptAccess&quot; value=&quot;sameDomain&quot; /&gt;
 &lt;param name=&quot;allowFullScreen&quot; value=&quot;false&quot; /&gt;
 &lt;param name=&quot;quality&quot; value=&quot;high&quot; /&gt;
 &lt;param name=&quot;bgcolor&quot; value=&quot;#ffffff&quot; /&gt;
 &lt;param name=&quot;wmode&quot; value=&quot;transparent&quot; /&gt;
 &lt;param name=&quot;allowScale&quot; value=&quot;false&quot; /&gt;
 &lt;param name=&quot;src&quot; value=&quot;mouse.swf&quot; /&gt;
 &lt;param name=&quot;allowfullscreen&quot; value=&quot;false&quot; /&gt;
 &lt;embed id=&quot;followers&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;250&quot; height=&quot;150&quot; src=&quot;mouse.swf&quot; allowscale=&quot;false&quot; wmode=&quot;transparent&quot; bgcolor=&quot;#ffffff&quot; quality=&quot;high&quot; allowfullscreen=&quot;false&quot; allowscriptaccess=&quot;sameDomain&quot; align=&quot;middle&quot; name=&quot;follower&quot;&gt;&lt;/embed&gt;
 &lt;/object&gt;
&lt;/div&gt;
</pre>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7217075623453662";
google_ad_slot = "4831550702";
google_ad_width = 300;
google_ad_height = 250;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<center><font-size="9px">Advertisement</font></center></p>
<p>Don’t forget to share the post on your favorite website. It may also help someone somewhere.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techmug.com/jmouse-follower/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

