<?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>Web Style Press, Best Practices from all the Web, Build Better Websites &#187; swap</title>
	<atom:link href="http://www.webstylepress.com/tag/swap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webstylepress.com</link>
	<description>Web VS Style</description>
	<lastBuildDate>Mon, 26 Dec 2011 10:35:53 +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>Simple RollOver Swap Image</title>
		<link>http://www.webstylepress.com/simple-rollover-swap-image/</link>
		<comments>http://www.webstylepress.com/simple-rollover-swap-image/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 09:11:47 +0000</pubDate>
		<dc:creator>Hiroshi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[swap]]></category>

		<guid isPermaLink="false">http://www.webstylepress.com/?p=361</guid>
		<description><![CDATA[Adobe Dreamweaver offers a way to Swap Images by adding javascript through its behaviours which uses following functions: function MM_swapImgRestore&#40;&#41; function MM_findObj&#40;n, d&#41; function MM_swapImage&#40;&#41; function MM_preloadImages&#40;&#41; And at OnMouseOver and OnMouseOut events you can swap images, but that method adds a lot of javascript code into your pages. There is another very simple and [...]<p><a href="http://www.webstylepress.com/simple-rollover-swap-image/">Simple RollOver Swap Image</a> is a post from: <a href="http://www.webstylepress.com">Web Style Press, Best Practices from all the Web, Build Better Websites</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Adobe Dreamweaver offers a way to Swap Images by adding javascript through its behaviours which uses following functions:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> MM_swapImgRestore<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #003366; font-weight: bold;">function</span> MM_findObj<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span> d<span style="color: #009900;">&#41;</span>
<span style="color: #003366; font-weight: bold;">function</span> MM_swapImage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #003366; font-weight: bold;">function</span> MM_preloadImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>And at OnMouseOver and OnMouseOut events you can swap images, but that method adds a lot of javascript code into your pages.</p>
<p>There is another very simple and easy way of swapping images. You need a single js file of 1 kb that will be sufficient for all the pages of your website. Moreover implementation of code is as easy as think and done.  </p>
<p><span id="more-361"></span></p>
<p>This is the implementation of Easy and Simple Image Swap by <a rel="nofollow" target="_blank" href="http://jehiah.cz/archive/simple-swap" target="_blank">Jehiah Czebotar</a>.</p>
<p>Create a js file i.e. rollover.js and put following code in that:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> SimpleSwap<span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span>which<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  el.<span style="color: #660066;">src</span><span style="color: #339933;">=</span>el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span>which <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;origsrc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> SimpleSwapSetup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>x.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> oversrc <span style="color: #339933;">=</span> x<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;oversrc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>oversrc<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// preload image</span>
    <span style="color: #006600; font-style: italic;">// comment the next two lines to disable image pre-loading</span>
    x<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">oversrc_img</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    x<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">oversrc_img</span>.<span style="color: #660066;">src</span><span style="color: #339933;">=</span>oversrc<span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// set event handlers</span>
    x<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">onmouseover</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Function</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SimpleSwap(this,'oversrc');&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    x<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">onmouseout</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Function</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SimpleSwap(this);&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// save original src</span>
    x<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;origsrc&quot;</span><span style="color: #339933;">,</span>x<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">var</span> PreSimpleSwapOnload <span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>window.<span style="color: #000066;">onload</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span> window.<span style="color: #000066;">onload</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
window.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>PreSimpleSwapOnload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> SimpleSwapSetup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Include it in web page like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;rollover.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Finally place your image like following.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;ss_img.gif&quot; oversrc=&quot;ss_img_over.gif&quot;&gt;</pre></div></div>

<p><strong>oversrc</strong> will handle the hover state of image. Now you will just place image and then point its hover state image in <strong>oversrc</strong> and you are done.</p>
<p><span class="downloadfile"><a href='http://www.webstylepress.com/wp-content/uploads/2008/10/rollover-image.rar'>Download Simple Image Swap Example</a></span></p>
<p><a href="http://www.webstylepress.com/simple-rollover-swap-image/">Simple RollOver Swap Image</a> is a post from: <a href="http://www.webstylepress.com">Web Style Press, Best Practices from all the Web, Build Better Websites</a></p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.webstylepress.com/use-any-font-in-webpages-as-text/" title="Use Any Font in Webpages As Text">Use Any Font in Webpages As Text</a></li><li><a href="http://www.webstylepress.com/auto-resize-browser-window-to-image-size/" title="Auto Resize Browser Window To Image Size">Auto Resize Browser Window To Image Size</a></li><li><a href="http://www.webstylepress.com/change-image-opacity-easily-using-css-js/" title="Change Image Opacity Easily Using CSS or JS">Change Image Opacity Easily Using CSS or JS</a></li><li><a href="http://www.webstylepress.com/advanced-js-calendar/" title="Advanced JS Calendar">Advanced JS Calendar</a></li><li><a href="http://www.webstylepress.com/simple-js-calendar/" title="Create Simple Javascript Based Calendar">Create Simple Javascript Based Calendar</a></li><li><a href="http://www.webstylepress.com/javascript-essentials-part-6/" title="Javascript Essentials Part 6">Javascript Essentials Part 6</a></li><li><a href="http://www.webstylepress.com/javascript-essentials-part-5/" title="Javascript Essentials Part 5">Javascript Essentials Part 5</a></li><li><a href="http://www.webstylepress.com/javascript-essentials-part-4/" title="Javascript Essentials Part 4">Javascript Essentials Part 4</a></li><li><a href="http://www.webstylepress.com/javascript-essentials-part-3/" title="Javascript Essentials Part 3">Javascript Essentials Part 3</a></li><li><a href="http://www.webstylepress.com/javascript-essentials-part-2/" title="Javascript Essentials Part 2">Javascript Essentials Part 2</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.webstylepress.com/simple-rollover-swap-image/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

