<?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>lightyeardesign.com &#187; Javascript</title>
	<atom:link href="http://lightyeardesign.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://lightyeardesign.com</link>
	<description>Design.  Develop.  Defy.</description>
	<lastBuildDate>Wed, 29 Jun 2011 19:03:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Javascript rotating features section</title>
		<link>http://lightyeardesign.com/2009/04/javascript-rotating-features-section/</link>
		<comments>http://lightyeardesign.com/2009/04/javascript-rotating-features-section/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 18:42:19 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://lightyeardesign.com/?p=25</guid>
		<description><![CDATA[Nothing catches the eye like a rotating features section on a website&#8217;s home page.  This can easily be accomplished with Javascript, and we will show you how. First, you will need to create your site layout, banner sized, and CSS code.  Once you have this foundation laid out, you can add your Javascript code.  Our Features [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing catches the eye like a rotating features section on a website&#8217;s home page.  This can easily be accomplished with Javascript, and we will show you how.<span id="more-25"></span></p>
<p>First, you will need to create your site layout, banner sized, and CSS code.  Once you have this foundation laid out, you can add your Javascript code.  Our Features section will consist of 6 rotating images, with corresponding text and links (You can view a working example at the <a title="View a rotating, Javascript-driven Featurs section at the Univeristy of Missouri home site." href="http://www.umsystem.edu">University of Missouri website</a> ).   Create a new .js file to store your code; we called ours bannerRotator.js, but any name will suffice.</p>
<p>We will create Javascript arrays to store our image/features information:<br />
[js]var adImages = new Array();<br />
  // Enter the names of the images below<br />
  // REMEMBER TO CHANGE THE CODE ON INDEX.SHTML TO REFLECT IMAGE 0 HERE<br />
  adImages[0]=&quot;&lt;a href=&quot;/images/features/090424_summit.jpg&quot;&gt;/images/features/090424_summit.jpg&lt;/a&gt;&quot;;<br />
  adImages[1]=&quot;&lt;a href=&quot;/images/features/090424_sustain.jpg&quot;&gt;/images/features/090424_sustain.jpg&lt;/a&gt;&quot;;<br />
  adImages[2]=&quot;&lt;a href=&quot;/images/features/090406_mob.jpg&quot;&gt;/images/features/090406_mob.jpg&lt;/a&gt;&quot;;<br />
  adImages[3]=&quot;&lt;a href=&quot;/images/features/090414_rocket.jpg&quot;&gt;/images/features/090414_rocket.jpg&lt;/a&gt;&quot;;<br />
  adImages[4]=&quot;&lt;a href=&quot;/images/features/090416_power.jpg&quot;&gt;/images/features/090416_power.jpg&lt;/a&gt;&quot;;<br />
  adImages[5]=&quot;&lt;a href=&quot;/images/features/090424_nerds.jpg&quot;&gt;/images/features/090424_nerds.jpg&lt;/a&gt;&quot;;<br />
  adImages[6]=&quot;&lt;a href=&quot;http://www.umsystem.edu/images/features/090402_dream.jpg&quot;&gt;http://www.umsystem.edu/images/features/090402_dream.jpg&lt;/a&gt;&quot;;<br />
 <br />
var adBackground = new Array();<br />
//Enter the corresponding background colors<br />
  adBackground[0]=&quot;url(/images/highlightsarrow.gif) no-repeat transparent left center&quot;;<br />
  adBackground[1]=&quot;url(/images/highlightsarrow.gif) no-repeat transparent left center&quot;;<br />
  adBackground[2]=&quot;url(/images/highlightsarrow.gif) no-repeat transparent left center&quot;;<br />
  adBackground[3]=&quot;url(/images/highlightsarrow.gif) no-repeat transparent left center&quot;;<br />
  adBackground[4]=&quot;url(/images/highlightsarrow.gif) no-repeat transparent left center&quot;;<br />
  adBackground[5]=&quot;url(/images/highlightsarrow.gif) no-repeat transparent left center&quot;;<br />
  adBackground[6]=&quot;url(/images/highlightsarrow.gif) no-repeat transparent left center&quot;;<br />
 <br />
var adText = new Array();<br />
//Enter the descriptive title<br />
   adText[0] = &quot;Energy summit&quot;;<br />
   adText[1] = &quot;Sustain Mizzou&quot;;<br />
   adText[2] = &quot;Mobster research&quot;;<br />
   adText[3] = &quot;Rocket launch&quot;;<br />
   adText[4] = &quot;Biomass power&quot;;<br />
   adText[5] = &quot;Nerd campaign&quot;;<br />
   adText[6] = &quot;Dream jobs&quot;;<br />
var adLink = new Array();<br />
//Enter the URL to the full story<br />
   adLink[0] = &quot;/story/1.html&quot;;<br />
   adLink[1] = &quot;/story/2.html&quot;;<br />
   adLink[2] = &quot;/story/3.html&quot;;<br />
   adLink[3] = &quot;/story/4.html&quot;;<br />
   adLink[4] = &quot;/story/5.html&quot;;<br />
   adLink[5] = &quot;/story/6.html&quot;;<br />
   adLink[6] = &quot;/story/7.html&quot;;[/js]<br />
Next, we will create a function to rotate the images:<br />
[js]function rotate() {<br />
   if(document.images) {<br />
 </p>
<p>        if (thisAd == imgCt) {<br />
            thisAd = 0<br />
       }</p>
<p>       document.adBanner.src=adImages[thisAd];</p>
<p>       featureTitle(thisAd)<br />
       thisAd++<br />
 <br />
      setTimeout(&quot;rotate()&quot;, 9 * 1000)</p>
<p>  }<br />
}[/js]<br />
Next, a function to store all of the generated HTML in an array (and push to the adText element, via innerHTML):<br />
[js]function featureTitle(thisAd)  {</p>
<p>   var totalArray = &quot;&amp;lt;br /&amp;gt;&quot;;<br />
   var newValue = &quot;&quot;;<br />
   var newHref = &quot;&quot;;</p>
<p>   for (i=0;i&amp;lt;adText.length;i++)<br />
   {<br />
  <br />
      if (i == thisAd)<br />
      {<br />
     <br />
         newValue = &quot;&amp;lt;strong&amp;gt;&amp;lt;a style=\&quot;color: #fff;_margin-left:-15px;background: &quot; + adBackground[i] + &quot;;\&quot; href=\&quot;&quot; + adLink[i] + &quot;\&quot;&amp;gt;&quot; + adText[i] + &quot;&amp;lt;/a&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;script language=\&quot;javascript\&quot; type=\&quot;text/javascript\&quot;&amp;gt;document.getElementById(&#8216;newBg&#8217;).href=adLink[&quot; + i + &quot;];&amp;lt;/script&amp;gt;&quot;;<br />
     <br />
      } else {     <br />
     <br />
         newValue = &quot;&amp;lt;a onMouseOver=\&quot;document.adBanner.src=adImages[&quot; + i + &quot;]; document.getElementById(&#8216;newBg&#8217;).href=adLink[&quot; + i + &quot;]; featureTitle(&quot; + i + &quot;);\&quot; href=\&quot;#\&quot;&amp;gt;&quot; + adText[i] + &quot;&amp;lt;/a&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&quot;;<br />
          <br />
      }</p>
<p>     <br />
      totalArray = totalArray + newValue;<br />
   }</p>
<p>   newVar = totalArray;<br />
   document.getElementById(&#8216;adText&#8217;).innerHTML = newVar;<br />
  <br />
}[/js]<br />
Finally, a function to load the features:<br />
[js]function loadStory(i) {</p>
<p> document.adBanner.src=adImages[i];</p>
<p>}[/js]<br />
Add the following code to the .js file:<br />
[js]thisAd = 0;</p>
<p>imgCt = adImages.length[/js]<br />
The thisAD variable resets the variable counter, and imgCT determined the length of the adImages image.</p>
<p>In the &lt;HEAD&gt; tag of your web page with the features section, make sure that you reference your .JS file.   Our file is in the scripts directory, and is entitled bannerRotator.js:<br />
[js]&amp;lt;script type=&quot;text/javascript&quot; src=&quot;/scripts/bannerRotator.js&quot;&amp;gt;&amp;lt;/script&amp;gt;[/js]<br />
Finally, add the javascript code required to activate the rotate function:<br />
[js]&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;<br />
 $(document).ready(function(){<br />
    rotate();<br />
  });<br />
&amp;lt;/script&amp;gt;<br />
[/js]<br />
All of the code is in place.  All that is required is a bit of tweaking on your part in order to ensure that the images and text line up.</p>
]]></content:encoded>
			<wfw:commentRss>http://lightyeardesign.com/2009/04/javascript-rotating-features-section/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

