<?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>WebDesign &#38; Such &#187; load random image</title>
	<atom:link href="http://webdesignandsuch.com/tag/load-random-image/feed/" rel="self" type="application/rss+xml" />
	<link>http://webdesignandsuch.com</link>
	<description>a Beantown Design Production</description>
	<lastBuildDate>Wed, 08 Sep 2010 02:29:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to load a random image on pageload ~ Javascript</title>
		<link>http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/</link>
		<comments>http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 10:27:10 +0000</pubDate>
		<dc:creator>ilz</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[load random image]]></category>

		<guid isPermaLink="false">http://webdesignandsuch.com/?p=386</guid>
		<description><![CDATA[On my portfolio website I have an About page, where I explain&#8230; who I am of course! So I have a picture of myself in the sidebar, but got the idea that it&#8217;d be nice to have the picture change randomly on page load. I looked around at a few different options. Some were Javascript, [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://webdesignandsuch.com/imagesForPosts/me.jpg" title="Beantown Design" class="alignnone" width="560" height="332" /></p>
<p>On my portfolio website I have an <strong><a href="http://beantowndesign.com/about.html">About page</a></strong>, where I explain&#8230; who I am of course! So I have a picture of myself in the sidebar, but got the idea that it&#8217;d be nice to have the picture change randomly on page load. I looked around at a few different options. Some were Javascript, some were PHP. It wasn&#8217;t worth turning the page into a PHP page just for this effect, so I went with Javascript. There are a lot of different options, but here&#8217;s the one I went with. </p>
<p><span id="more-386"></span></p>
<p>I made a div to surround the image, with the class of &#8220;me-box&#8221;. I gave this div a border, so the images will all appear to have a border when they are loaded. Next comes the Javascript code. This is where you give the src to your images. This code is put right in the body of your page where you want the images to appear, not in he head tag. A quick little piece of code that got the job done exactly like I wanted!</p>
<p><a href="http://beantowndesign.com/about.html">See the random image loading in action.</a></p>
<div class="codeBox">
<p>&lt;div class=&#8221;me-box&#8221;&gt;</p>
<p>&lt;script language=&#8221;JavaScript&#8221;&gt;<br />
function banner() { } ; b = new banner() ; n = 0<br />
b[n++]= &#8220;&lt;img name=randimg src=&#8217;images/me.jpg&#8217; &gt;&#8221;<br />
b[n++]= &#8220;&lt;img name=randimg src=&#8217;images/me2.jpg&#8217; &gt;&#8221;<br />
b[n++]= &#8220;&lt;img name=randimg src=&#8217;images/me4.jpg&#8217; &gt;&#8221;<br />
b[n++]= &#8220;&lt;img name=randimg src=&#8217;images/me5.jpg&#8217; &gt;&#8221;<br />
b[n++]= &#8220;&lt;img name=randimg src=&#8217;images/me6.jpg&#8217; &gt;&#8221;<br />
b[n++]= &#8220;&lt;img name=randimg src=&#8217;images/me3.jpg&#8217; &gt;&#8221;<br />
i=Math.floor(Math.random() * n) ;<br />
document.write( b[i] )<br />
&lt;/script&gt;</p>
<p>&lt;/div&gt;</p></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://webdesignandsuch.com/2009/11/using-smooth-scroll-with-page-anchors-and-javascript/" rel="bookmark" class="crp_title">Using Smooth Scroll with Page Anchors and Javascript</a></li><li><a href="http://webdesignandsuch.com/2009/07/how-to-add-the-current-date-to-your-webpage-with-javascipt-2/" rel="bookmark" class="crp_title">Add Current Date to webpage with Javascipt</a></li><li><a href="http://webdesignandsuch.com/2009/07/how-to-add-the-current-date-to-your-webpage-with-javascipt/" rel="bookmark" class="crp_title">How to Add the Current Date to your webpage with Javascipt</a></li><li><a href="http://webdesignandsuch.com/2009/09/css-stylesheet-switcher-javascript-dreamweaver-kaos/" rel="bookmark" class="crp_title">CSS stylesheet switcher ~ Javascript, Dreamweaver, Kaos</a></li><li><a href="http://webdesignandsuch.com/2010/06/how-to-refresh-reload-a-webpage-with-jquery/" rel="bookmark" class="crp_title">How to refresh / reload a webpage with jQuery</a></li></ul></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/&amp;title=How+to+load+a+random+image+on+pageload+%7E+Javascript" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/&amp;title=How+to+load+a+random+image+on+pageload+%7E+Javascript" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/&amp;bm_description=How+to+load+a+random+image+on+pageload+%7E+Javascript&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/&amp;title=How+to+load+a+random+image+on+pageload+%7E+Javascript" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/&amp;title=How+to+load+a+random+image+on+pageload+%7E+Javascript" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/&amp;title=How+to+load+a+random+image+on+pageload+%7E+Javascript" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=How+to+load+a+random+image+on+pageload+%7E+Javascript+-+http://b2l.me/ap7bw2&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://webdesignandsuch.com/2009/09/how-to-load-a-random-image-on-pageload-javascript/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
