<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Coding Mix</title><link>http://www.codingmix.com/search/label/Javascript%20tutorials</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/codingmix/Javascript/Tutorials" /><description></description><language>en</language><managingEditor>noreply@blogger.com (Csabi)</managingEditor><lastBuildDate>Thu, 23 Feb 2012 19:15:09 PST</lastBuildDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">9</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage><feedburner:info uri="codingmix/javascript/tutorials" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>codingmix/Javascript/Tutorials</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>How to change title bar message using Javascript</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/FcYNq5UlyQw/change-title-bar-message-text.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 12 Nov 2010 06:31:14 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8072308504604825522</guid><description>For those who doesn`t know what is the title bar: The title bar is the top part of the browser window where the website`s (page) title is shown: &lt;img style="float:right; margin:0 50px 0 0;cursor:pointer; cursor:hand;width: 194px; height: 30px;" src="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TNwEz9GZFMI/AAAAAAAAAQw/13pgQILky58/s1600/title%2Bbar.png" border="0" alt="change title bar message"id="BLOGGER_PHOTO_ID_5538306932380079298" /&gt;In this lesson I will show you how the title bar message (text) can be changed using only Javascript.&lt;div id="full-post"&gt;&lt;br /&gt;The title bar message can be changed easily using the following property:&lt;div class="code"&gt;&lt;b&gt;document.title&lt;/b&gt;&lt;/div&gt;And the easiest way to use it is:&lt;div class="code"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;document.title = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;But there are many other, funny ways to change the title bar message:&lt;h2 style="background:none;color:#555;font-weight:bold;"&gt;Changing the title bar message&lt;/h2&gt;&lt;div class="code"&gt;&lt;center&gt;&lt;input type="text" id="newtitle" value="New title bar message..."/&gt;&lt;input type="button" value="Change title" onclick="changetitle(document.getElementById('newtitle').value);"/&gt;&lt;/center&gt;&lt;script type="text/javascript"&gt;function changetitle(to){document.title = to;}&lt;/script&gt;&lt;/div&gt;This is done by the following script:&lt;div class="code"&gt;&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle&amp;quot; value=&amp;quot;New title bar message...&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Change title&amp;quot; onclick=&amp;quot;changetitle(document.getElementById('newtitle').value);&amp;quot;/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function changetitle(changeto){&lt;br /&gt;   document.title = changeto;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;h2 style="background:none;color:#555;font-weight:bold;"&gt;Dynamic title bar message&lt;/h2&gt;&lt;div class="code"&gt;&lt;center&gt;Title 1:&lt;input type="text" id="newtitle1" value="--"/&gt;&lt;br /&gt;Title 2:&lt;input type="text" id="newtitle2" value="----"/&gt;&lt;br /&gt;Title 3:&lt;input type="text" id="newtitle3" value="------"/&gt;&lt;br /&gt;Title 4:&lt;input type="text" id="newtitle4" value="--------"/&gt;&lt;br /&gt;Title 5:&lt;input type="text" id="newtitle5" value="----------"/&gt;&lt;br /&gt;&lt;input type="button" value="Start" onclick="clearTimeout(timeouttitle);starttitle();"/&gt;&lt;input type="button" value="Stop" onclick="clearTimeout(timeouttitle);"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Or loop from 0% to 100%&lt;/b&gt;&lt;br /&gt;&lt;input type="button" value="Start" onclick="clearTimeout(timeouttitleb);starttitleb();"/&gt;&lt;input type="button" value="Stop" onclick="clearTimeout(timeouttitleb);"/&gt;&lt;/center&gt;&lt;script type="text/javascript"&gt;var xaz=0;var timeouttitleb;var u=1;var timeouttitle;function starttitle(){document.title = document.getElementById('newtitle' + u).value;u++;if(u &gt; 5){u=1;}timeouttitle=setTimeout(starttitle,1000);}function starttitleb(){document.title = xaz + "%";xaz++;timeouttitleb=setTimeout(starttitleb,500);if(xaz&gt;100){clearTimeout(timeouttitleb);xaz=0;}}&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;Here is the script for the first example (loop through the 5 titles):&lt;div class="code"&gt;&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle1&amp;quot; value=&amp;quot;--&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Title 2:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle2&amp;quot; value=&amp;quot;----&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Title 3:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle3&amp;quot; value=&amp;quot;------&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Title 4:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle4&amp;quot; value=&amp;quot;--------&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Title 5:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle5&amp;quot; value=&amp;quot;----------&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Start&amp;quot; onclick=&amp;quot;clearTimeout(timeout);starttitle();&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Stop&amp;quot; onclick=&amp;quot;clearTimeout(timeout);&amp;quot;/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var i=1;&lt;br /&gt;var timeout;&lt;br /&gt;function starttitle(){&lt;br /&gt;   document.title = document.getElementById('newtitle' + i).value;&lt;br /&gt;   i++;&lt;br /&gt;   if(i &amp;gt; 5){&lt;br /&gt;      i=1; &lt;span style="color:green;"&gt;//When the 5th title is used go back to the first one&lt;/span&gt;&lt;br /&gt;   }&lt;br /&gt;   timeout = setTimeout(starttitle,1000); &lt;span style="color:green;"&gt;//1000 is the number of milliseconds between each change&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;br /&gt;And here is the script for the second example (loop from 1% to 100%):&lt;div class="code"&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Start&amp;quot; onclick=&amp;quot;clearTimeout(timeout);starttitle();&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Stop&amp;quot; onclick=&amp;quot;clearTimeout(timeout);&amp;quot;/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var number=0;&lt;br /&gt;var timeout;&lt;br /&gt;function starttitle(){&lt;br /&gt;   document.title = number + &amp;quot;%&amp;quot;;&lt;br /&gt;   number++;&lt;br /&gt;   timeout = setTimeout(starttitle,500);&lt;br /&gt;   if(number &amp;gt; 100){&lt;br /&gt;      clearTimeout(timeout); &lt;span style="color:green;"&gt;//When reach 100% stop and set &lt;i&gt;number&lt;/i&gt; back to 0&lt;/span&gt;&lt;br /&gt;      number = 0; &lt;span style="color:green;"&gt;//Without this line the script will be able to run only once&lt;/span&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;These where just some examples, but using this property you can change the title bar in almost any way. If you have any question or somethings is not working then let me know it in a comment!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8072308504604825522?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/C_akPCZ_XS4Owme65mJBrxuh3Wc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C_akPCZ_XS4Owme65mJBrxuh3Wc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/C_akPCZ_XS4Owme65mJBrxuh3Wc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C_akPCZ_XS4Owme65mJBrxuh3Wc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/FcYNq5UlyQw" height="1" width="1"/&gt;</description><media:thumbnail url="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TNwEz9GZFMI/AAAAAAAAAQw/13pgQILky58/s72-c/title%2Bbar.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/change-title-bar-message-text.html</feedburner:origLink></item><item><title>Searching in a list with Javascript</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/yq4MdKnE6S8/searching-in-list-with-javascript.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 10 Sep 2010 08:07:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8039075891943670893</guid><description>In this tutorial I will show you how to create a script what searches in a list (li or table) for the inputted text at each press of a button. Because I can`t explain better what the script can do, here is an example: &lt;div id="full-post"&gt;&lt;div class="code"&gt;&lt;input type="text" id="searchbar" onKeyUp="searchit();"/&gt;&lt;ul style="list-style:none;margin:0px;padding:0 15px;"&gt;&lt;li class="search"&gt;Coffee&lt;/li&gt;&lt;li class="search"&gt;Milk&lt;/li&gt;&lt;li class="search"&gt;Chees&lt;/li&gt;&lt;li class="search"&gt;Tea&lt;/li&gt;&lt;li class="search"&gt;Orange&lt;/li&gt;&lt;li class="search"&gt;Sugar&lt;/li&gt;&lt;li class="search"&gt;Honey&lt;/li&gt;&lt;li class="search"&gt;Milkshake&lt;/li&gt;&lt;/ul&gt;&lt;script type="text/javascript"&gt;function searchit(){var keyword = document.getElementById('searchbar').value;for(var i=0;i&lt;=document.getElementsByTagName('li').length-1;i++){if(document.getElementsByTagName('li')[i].className == 'search'){if(document.getElementsByTagName('li')[i].innerHTML.toLowerCase().indexOf(keyword.toLowerCase()) == -1){document.getElementsByTagName('li')[i].style.height = '0px';}else{document.getElementsByTagName('li')[i].style.height = '20px';}}}}&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;How it works:&lt;/b&gt;&lt;br /&gt;The script loops through all the 'li' elements from the document and searches for the ones with class "search". From these 'li' elements it resizes to 0 pixels the ones what don`t contain the searched word, and it resizes to its original size the ones what contain the searched word: &lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.search {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;searchbar&amp;quot; onKeyUp=&amp;quot;searchit();&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;ul style=&amp;quot;list-style:none;margin:0px;padding:0 15px;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Coffee&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Milk&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Chees&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Tea&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Orange&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Sugar&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Honey&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Milkshake&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function searchit(){&lt;br /&gt;   var keyword = document.getElementById('searchbar').value;&lt;br /&gt;   for(var i=0;i&amp;lt;document.getElementsByTagName('li').length;i++){&lt;br /&gt;      if(document.getElementsByTagName('li')[i].className == 'search'){&lt;br /&gt;         if(document.getElementsByTagName('li')[i].innerHTML.toLowerCase().indexOf(keyword.toLowerCase()) == -1){&lt;br /&gt;            document.getElementsByTagName('li')[i].style.height = '0px';&lt;br /&gt;         }&lt;br /&gt;         else{&lt;br /&gt;            document.getElementsByTagName('li')[i].style.height = '20px';&lt;br /&gt;         }&lt;br /&gt;      } &lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;Note: The list must have the &lt;i&gt;overflow:hidden;&lt;/i&gt; property!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8039075891943670893?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KAxiv0j7JMFCGWKovisvfEhVIEI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KAxiv0j7JMFCGWKovisvfEhVIEI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KAxiv0j7JMFCGWKovisvfEhVIEI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KAxiv0j7JMFCGWKovisvfEhVIEI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/yq4MdKnE6S8" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://www.codingmix.com/2010/09/searching-in-list-with-javascript.html</feedburner:origLink></item><item><title>Creating a Javascript Slideshow part 6</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/dtw0GOgFNZw/creating-javascript-slideshow-part-6.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 29 Aug 2010 05:44:16 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8299546093059820701</guid><description>Before reading this please read the &lt;a href="http://www.codingmix.com/2010/07/how-to-create-slideshow-without-jquery.html" title="Javascript slideshow"&gt;first parts&lt;/a&gt; of the tutorial.&lt;br /&gt;This is the last part of this tutorials series. In this part of the tutorial we will finish the slideshow. &lt;div id="full-post"&gt;&lt;br /&gt;&lt;b&gt;Positioning the buttons in a better way&lt;/b&gt;&lt;br /&gt;Let`s make the slideshow controls look better. My idea is to place the "Prev" button in the left corner, the "Slow Medium Fast" button in the middle of the div and the "Next" button in the right corner, each with a margin of 5px. Here is how I did:&lt;div class="code"&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;&lt;span style="color:red;"&gt;text-align: center;&lt;/span&gt;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot; style=&amp;quot;&lt;span style="color:red;"&gt;float:left;margin-left:5px;&lt;/span&gt;&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot; style=&amp;quot;margin:0 1px;&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot; style=&amp;quot;&lt;span style="color:red;"&gt;float:right;margin-right:5px;&lt;/span&gt;&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Showing the current image number&lt;/b&gt;&lt;br /&gt;This will be the last step in finishing the slideshow. Now we will place a message like this: 3/5 ,the number of the current image/images number.&lt;br /&gt;I think it would be the best to place it in the right upper corner of the slideshow with a black transparent background (so we will need two div`s, one for the background and one for the numbers, just like at the controls).&lt;br /&gt;First let`s create the two divs:&lt;div class="code"&gt;&amp;lt;div id=&amp;quot;imagesnumberbg&amp;quot; style=&amp;quot;background:black;position:absolute;width:50px;height:20px;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;imagesnumber&amp;quot; style=&amp;quot;position:absolute;width:50px;height:20px;text-align:center;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/div&gt;Place them right before the &lt;i&gt;loadingimage&lt;/i&gt; div.&lt;br /&gt;For now the two divs are empty and are placed in the left corner. Because the &lt;i&gt;position:absolute;&lt;/i&gt; property we can`t use the &lt;i&gt;float:right;&lt;/i&gt; property, instead we will need to use the &lt;i&gt;margin-left:&lt;/i&gt; property, but we need to calculate the distance required. &lt;br /&gt;We will do this by adding some code to the &lt;i&gt;changeimage&lt;/i&gt; function. Here will come the code what will change the numbers, too. This entire piece of code will look like this: &lt;div class="code"&gt;var requiredmargin = parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('imagesnumberbg').style.width);&lt;br /&gt;   document.getElementById('imagesnumberbg').style.marginLeft = requiredmargin + 'px';&lt;br /&gt;   document.getElementById('imagesnumber').style.marginLeft = requiredmargin + 'px';&lt;br /&gt;   document.getElementById('imagesnumber').innerHTML = currentimage + '/' + (images.length - 1);&lt;/div&gt;&lt;br /&gt;&lt;b&gt;After all of these 6 parts of creating and styling the slideshow my code looks in the following way, yours should be the same:&lt;/b&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;background:black;color:white;&amp;quot; onMouseOver=&amp;quot;showcontrols();&amp;quot; onMouseOut=&amp;quot;hidecontrols();&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;imagesnumberbg&amp;quot; style=&amp;quot;background:black;position:absolute;width:50px;height:20px;filter:alpha(opacity=60);opacity:0.6;margin-left:400px;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;imagesnumber&amp;quot; style=&amp;quot;position:absolute;width:50px;height:20px;text-align:center;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;height:301px;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrolsbg&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;background:black;filter:alpha(opacity=60);opacity:0.6;z-index:-1;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;text-align: center;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot; style=&amp;quot;float:left;margin-left:5px;&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot; style=&amp;quot;margin:0 1px;&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot; style=&amp;quot;float:right;margin-right:5px;&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:red;"&gt;var requiredmargin = parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('imagesnumberbg').style.width);&lt;br /&gt;   document.getElementById('imagesnumberbg').style.marginLeft = requiredmargin + 'px';&lt;br /&gt;   document.getElementById('imagesnumber').style.marginLeft = requiredmargin + 'px';&lt;br /&gt;   document.getElementById('imagesnumber').innerHTML = currentimage + '/' + (images.length - 1);&lt;/span&gt;&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   waitimage();&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      positioningimage();&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = 1;&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image').style.marginTop = (parseInt(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function showcontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = 1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = 1;&lt;br /&gt;}&lt;br /&gt;function hidecontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = -1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function slideautomatically(timeinterval){&lt;br /&gt;   changeimage(1);&lt;br /&gt;   timeout = setTimeout(function(){slideautomatically(timeinterval)},timeinterval);&lt;br /&gt;}&lt;br /&gt;function stopsliding(){&lt;br /&gt;   clearTimeout(timeout);&lt;br /&gt;   document.getElementById('startslideshowbutton').innerHTML = &amp;quot;&amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);\&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);\&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);\&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;b&gt;And here is the slideshow:&lt;/b&gt; &lt;a onClick="previewslideshow();" style="color:green;font-weight:bold;"&gt;Start it&lt;/a&gt;&lt;br /&gt;(In the preview the Stop slideshow button is not working because the new window is written by Javascript and it can`t format well all the quotes - but else it works :D )&lt;br /&gt;If something is not working or just have a question, don`t hesitate, ASK!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8299546093059820701?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hJdBTKZgkkb6UHvdAdwvqW4ja9E/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hJdBTKZgkkb6UHvdAdwvqW4ja9E/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hJdBTKZgkkb6UHvdAdwvqW4ja9E/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hJdBTKZgkkb6UHvdAdwvqW4ja9E/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/dtw0GOgFNZw" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-6.html</feedburner:origLink></item><item><title>Javascript - get elements by class</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/1f84c4_20cs/javascript-get-elements-by-class.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Thu, 09 Sep 2010 14:48:23 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6053498948888109142</guid><description>I will show you two ways to get an element by class: using getElementsByTagName or creating a getElementByClass function:&lt;div id="full-post"&gt;&lt;br /&gt;&lt;b&gt;1. Using getElementsByTagName&lt;/b&gt;&lt;br /&gt;This code loops through each element of the page and check`s it`s class name:&lt;br /&gt;&lt;div class="code"&gt;for(var i=0;i&amp;lt;document.getElementsByTagName('*').length;i++){&lt;br /&gt;   if(document.getElementsByTagName('*')[i].className == 'YOUR-CLASS'){&lt;br /&gt;      document.getElementsByTagName('*')[i].style.backgroundColor = 'black';&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;2. Creating a getElementsByClass function&lt;/b&gt;&lt;br /&gt;This code creates the getElementsByClass function what returns an array of elements with the selected class name:&lt;div class="code"&gt;document.getElementsByClass = function(class){&lt;br /&gt;   var itemsfound = new Array;&lt;br /&gt;   var elements = document.getElementsByTagName('*');&lt;br /&gt;   for(var i=0;i&amp;lt;elements.length;i++){&lt;br /&gt;      if(elements[i].className == class){&lt;br /&gt;         itemsfound.push(elements[i]);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   return itemsfound;&lt;br /&gt;}&lt;/div&gt;Use it in the following way to select only the element with the specified index:&lt;div class="code"&gt;document.getElementsByClass('YOUR-CLASS')[0].style.backgroundColor = 'black';&lt;/div&gt;Or use this if you want to select each element:&lt;div class="code"&gt;for(var i=0;i&lt;=document.getElementsByClass('YOUR-CLASS').length;i++){&lt;br /&gt; document.getElementsByClass('YOUR-CLASS')[i].style.backgroundColor = 'black';&lt;br /&gt;}&lt;/div&gt;Note: Javascript is case sensitive&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6053498948888109142?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/nEhz5IBAf7C_HoBEasynvr6XQVk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nEhz5IBAf7C_HoBEasynvr6XQVk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/nEhz5IBAf7C_HoBEasynvr6XQVk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nEhz5IBAf7C_HoBEasynvr6XQVk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/1f84c4_20cs" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total><feedburner:origLink>http://www.codingmix.com/2010/08/javascript-get-elements-by-class.html</feedburner:origLink></item><item><title>Creating a Javascript Slideshow part 5</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/29JMLUz9Rrg/creating-javascript-slideshow-part-5.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 29 Aug 2010 05:32:06 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6046868732677861566</guid><description>Before reading this please read the first parts of this tutorials: &lt;a href="http://www.codingmix.com/2010/07/how-to-create-slideshow-without-jquery.html" title="slideshow"&gt;Part 1&lt;/a&gt;&lt;br /&gt;In this part we will add an automatic sliding option to our slideshow, whit 3 speed levels: slow, medium, fast. &lt;div id="full-post"&gt;Let`s make it:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Sliding the images automatically&lt;/b&gt;&lt;br /&gt;To slide the images automatically we need a function (name it &lt;i&gt;slideautomatically&lt;/i&gt;) what will start the &lt;i&gt;changeimage&lt;/i&gt; function again and again with a delays. We will make it using the &lt;i&gt;setTimeout&lt;/i&gt; funtion and we will adjust the speed by changing the delay (in milliseconds) between each run of the function. This function will be triggered by the three buttons: Slow, Medium and the Fast buttons using &lt;i&gt;onClick&lt;/i&gt; events. Each of these buttons will have as &lt;i&gt;parameter&lt;/i&gt; the delay between each run of the function in milliseconds. Name tha parameter &lt;i&gt;timeinterval&lt;/i&gt;&lt;br /&gt;The function should look like this: &lt;div class="code"&gt;function slideautomatically(timeinterval){&lt;br /&gt;   changeimage(1);&lt;br /&gt;   timeout = setTimeout(function(){slideautomatically(timeinterval)},timeinterval);   &lt;br /&gt;}&lt;/div&gt;Note: I have used a variable to store the timeout, because later will need to clear it.&lt;br /&gt;Now we need to create the buttons what will start this function:&lt;div class="code"&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;/div&gt;Place it between the Prev and Next buttons. &lt;br /&gt;&lt;br /&gt;After editing it my code look like this:&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;background:black;color:white;&amp;quot; onMouseOver=&amp;quot;showcontrols();&amp;quot; onMouseOut=&amp;quot;hidecontrols();&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;height:301px;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrolsbg&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;background:black;filter:alpha(opacity=60);opacity:0.6;z-index:-1;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   waitimage();&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      positioningimage();&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = 1;&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image').style.marginTop = (parseInt(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function showcontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = 1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = 1;&lt;br /&gt;}&lt;br /&gt;function hidecontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = -1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function slideautomatically(timeinterval){&lt;br /&gt;   changeimage(1);&lt;br /&gt;   timeout = setTimeout(function(){slideautomatically(timeinterval)},timeinterval);&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;Now the images are changed automatically but now we need a way to stop it. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Stop it&lt;/b&gt;&lt;br /&gt;To stop the automatic sliding we will need first a button to stop it by triggering a function. Call this function &lt;i&gt;stopsliding&lt;/i&gt;. We will place this button in the place of the "Slow Medium Fast" button by changing the content of the &lt;i&gt;startslideshowbutton&lt;/i&gt; span when the automatic sliding starts. We will change the content of the &lt;i&gt;startslideshowbutton&lt;/i&gt; span by changing the &lt;i&gt;onClick &lt;/i&gt; event of the "Slow Medium Fast" buttons from this: &lt;div class="code"&gt;onClick="slideautomatically(8000);"&lt;br /&gt;onClick="slideautomatically(4000);"&lt;br /&gt;onClick="slideautomatically(2000);"&lt;/div&gt;to this:&lt;div class="code"&gt;onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);&amp;quot;&lt;br /&gt;onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);&amp;quot;&lt;br /&gt;onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);&amp;quot;&lt;/div&gt;Note: The &lt;b&gt;&amp;amp;quot;&lt;/b&gt; character is used to replace a double quote. Because this is an inline Javascript event we &lt;b&gt;can`t&lt;/b&gt; use the &lt;b&gt;\"&lt;/b&gt; character instead.&lt;br /&gt;&lt;br /&gt;Now we just need to create the &lt;i&gt;stopsliding&lt;/i&gt; function:&lt;div class="code"&gt;function stopsliding(){&lt;br /&gt;   clearTimeout(timeout);&lt;br /&gt;   document.getElementById('startslideshowbutton').innerHTML = &amp;quot;&amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);\&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);\&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);\&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;/div&gt;The above function first clears the timeout so stops the automatic sliding and then it replaces the "Stop slideshow" button with the "Slow Medium Fast" buttons.&lt;br /&gt;&lt;br /&gt;Here is my code, yours should look the same: &lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;background:black;color:white;&amp;quot; onMouseOver=&amp;quot;showcontrols();&amp;quot; onMouseOut=&amp;quot;hidecontrols();&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;height:301px;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrolsbg&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;background:black;filter:alpha(opacity=60);opacity:0.6;z-index:-1;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   waitimage();&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      positioningimage();&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = 1;&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image').style.marginTop = (parseInt(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function showcontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = 1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = 1;&lt;br /&gt;}&lt;br /&gt;function hidecontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = -1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function slideautomatically(timeinterval){&lt;br /&gt;   changeimage(1);&lt;br /&gt;   timeout = setTimeout(function(){slideautomatically(timeinterval)},timeinterval);&lt;br /&gt;}&lt;br /&gt;function stopsliding(){&lt;br /&gt;   clearTimeout(timeout);&lt;br /&gt;   document.getElementById('startslideshowbutton').innerHTML = &amp;quot;&amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);\&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);\&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);\&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;If something is not clear ASK ME!&lt;br /&gt;Continue to &lt;a href="http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-6.html"&gt;part 6&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6046868732677861566?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Pdabf6eqRBN_Edt3Nc-VjbWViok/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Pdabf6eqRBN_Edt3Nc-VjbWViok/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Pdabf6eqRBN_Edt3Nc-VjbWViok/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Pdabf6eqRBN_Edt3Nc-VjbWViok/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/29JMLUz9Rrg" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-5.html</feedburner:origLink></item><item><title>Creating a Javascript Slideshow part 4</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/oUWFYzqy_cU/creating-javascript-slideshow-part-4.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Thu, 26 Aug 2010 08:59:47 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6665512325497740301</guid><description>Before reading this please read the previous parts:&lt;br /&gt;&lt;a href="http://www.codingmix.com/2010/07/how-to-create-slideshow-without-jquery.html"&gt;Creating a Javascript Slideshow part 1&lt;/a&gt;&lt;br /&gt;Now the slideshow can change the images, it can resize them and place them in the center. Now let`s make it more stylish: I will change the background color of the &lt;i&gt;slideshow&lt;/i&gt; div to &lt;b&gt;black&lt;/b&gt;, but you can leave it white if you like. (if you change it to black don`t forget to set the text color to white). &lt;div id="full-post"&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Loading...&lt;/b&gt;&lt;br /&gt;Another way to make it look better is to show a loading... message while the image is loaded: Something like this (with transparent background):&lt;div id="loadingimage" style="background:black;width:100px;height:20px;text-align:center;color:white;filter:alpha(opacity=60);opacity:0.6;"&gt;Loading...&lt;/div&gt;Placed over the image in the center. I think it will look great. :D so let`s code it.&lt;br /&gt;&lt;br /&gt;First create a div with the id &lt;i&gt;loadingimage&lt;/i&gt; inside the &lt;i&gt;slideshow&lt;/i&gt; div BEFORE the &lt;i&gt;slideshowimage&lt;/i&gt; div. I`we capitalized &lt;i&gt;before&lt;/i&gt; because this is important and you will see immediately why. Place inside your div the loading message, (I will use &lt;i&gt;Loading...&lt;/i&gt;) and change the background color to black.&lt;br /&gt;&lt;br /&gt;Now the loading message is displayed at the top of the slideshow and it`s always visible. Now we need to overlay it on the image and place it in the center. We will do this using only CSS, using the z-index property. If two or more thing are overlaying then there need`s to be and order to specify what element is in the front and what is behind. The element with the highest z-index value is in the front. This property works only with positioned elements, so set the position of the div to &lt;i&gt;absolute&lt;/i&gt;. Now set the height and the width, I will use 100px width and 20px height, and use the text-align:center; property to center the text inside the div.&lt;br /&gt;Now my &lt;i&gt;loadingimage&lt;/i&gt; div look in the following way:&lt;div class="code"&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;br /&gt;After setting the position to absolute the div overlays on the image, but now we need to place it in the center. We will make this using the margin property. &lt;br /&gt;Here is an easy way to calculate the pixels required to place the image in center:&lt;div class="code"&gt;w - the width of &lt;i&gt;slideshowimage&lt;/i&gt; div&lt;br /&gt;h - the height of &lt;i&gt;slideshowimage&lt;/i&gt; div&lt;br /&gt;wl - the width of &lt;i&gt;loadingimage&lt;/i&gt; div&lt;br /&gt;wh - the height of &lt;i&gt;loadingimage&lt;/i&gt; div&lt;br /&gt;&lt;br /&gt;Space required from left:&lt;br /&gt;(w - wl) / 2&lt;br /&gt;Mine is&lt;br /&gt;(400px - 100px) / 2 = 150px&lt;br /&gt;&lt;br /&gt;Space required from top:&lt;br /&gt;(h - hl) / 2&lt;br /&gt;Mine is &lt;br /&gt;(300px - 20px) / 2 = 140px&lt;/div&gt;Now we need just to create a snippet what will make the above calculations and change the &lt;i&gt;margin&lt;/i&gt; property. This can be changed using the &lt;i&gt;.style.margin&lt;/i&gt; property. This piece of code needs to be placed before the functions, at the beginning of the code, because the divs size will not change while the script is running and so we don`t need to change the &lt;i&gt;margin&lt;/i&gt; property each time we change the image. This snippet should look like this:&lt;div class="code"&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;/div&gt;Note: The &lt;i&gt;parseInt()&lt;/i&gt; converts a string to an integer (number), this is needed because the &lt;i&gt;.style.height&lt;/i&gt; and the &lt;i&gt;.style.width&lt;/i&gt; properties will return strings like "400px" not numbers like "400" - so if we want to make mathematical calculations we need to convert them to numbers. &lt;br /&gt;&lt;br /&gt;Now that the loading message is in the center we just need to make it transparent and to display it only when it`s needed.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Making the loading message div transparent&lt;/b&gt;&lt;br /&gt;We will make it transparent using CSS. For a better browser compatibility we will use two CSS properties in the following way: &lt;div class="code"&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;margin:150px 140px;&lt;span style="color:red;"&gt;filter:alpha(opacity=60);opacity:0.6;&lt;/span&gt;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Show the loading message only when needed&lt;/b&gt;&lt;br /&gt;To do this we will use the &lt;i&gt;waitimage&lt;/i&gt; function. In this function we will change the z-index value of the loading message so it will be on the top of the image. This code should look like this: &lt;div class="code"&gt;document.getElementById('loadingimage').style.zIndex = 1;&lt;/div&gt;Place it after the lines what check if the image is complete or not, because if the slideshow is showing the same image multiple times it will nod be loaded again so we don`t need to show the loading message. &lt;br /&gt;After the loading message is displayed we need to hide it again when the image is loaded. To do this we just need to set the zIndex of the loading message to -1 using the same method as above, but this code will need to be placed in the &lt;i&gt;positioningimage&lt;/i&gt; function after the image has been placed in the right place.&lt;br /&gt;&lt;br /&gt;My code look in the following way, your should look the same: &lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;background:black;color:white;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;height:301px;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   waitimage();&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      positioningimage();&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = 1;&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image').style.marginTop = (parseInt(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Styling the controls&lt;/b&gt;&lt;br /&gt;We will make the controls (the &lt;i&gt;slideshowcontrols&lt;/i&gt;) to look much better and it will be displayed only on mouseover, we will overlay the &lt;i&gt;slideshowcontrols&lt;/i&gt; div on the images (like the &lt;i&gt;loadingimage&lt;/i&gt; div) and we will show it only when the cursor is over the image.&lt;br /&gt;&lt;br /&gt;So let`s start:&lt;br /&gt;&lt;b&gt;Overlaying the controls on the images&lt;/b&gt;&lt;br /&gt;This is very simple, we will use only CSS:&lt;br /&gt;Add the following properties to the &lt;i&gt;slideshowcontrols&lt;/i&gt; div:&lt;br /&gt;- position:absolute;&lt;br /&gt;- height: 20px; (you can use any other value)&lt;br /&gt;- margin: -20xp 0; (use the same value as at the height but with a - in front)&lt;br /&gt;It should look like this: &lt;div class="code"&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;&amp;quot;&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Making it transparent&lt;/b&gt;&lt;br /&gt;We will make it transparent, but using a better method:&lt;br /&gt;At the loading message the text is transparent too, this is not a problem for the loading message, but the controls will look better with clear white buttons. To get rid of this problem we will create a second div, with the id &lt;i&gt;slideshowcontrolsbg&lt;/i&gt; with a black background and we will make this div transparent instead of &lt;i&gt;slideshowcontrols&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;Create the &lt;i&gt;slideshowcontrolsbg&lt;/i&gt; and place it right before the &lt;i&gt;slideshowcontrols&lt;/i&gt; div. &lt;br /&gt;Now add all the CSS properties from the &lt;i&gt;slideshowcontrols&lt;/i&gt; to it (&lt;b&gt;don`t&lt;/b&gt; remove the properties from &lt;i&gt;slideshowcontrols&lt;/i&gt;) and add the following properties, too:&lt;br /&gt;- background: black;&lt;br /&gt;- filter:alpha(opacity=60);&lt;br /&gt;- opacity:0.6;&lt;br /&gt;Now the two divs should look like this:&lt;div class="code"&gt;&amp;lt;div id=&amp;quot;slideshowcontrolsbg&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;background:black;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Display the controls only on mouseover&lt;/b&gt;&lt;br /&gt;Now we will make the controls to be displayed only when the cursor is over the image. We will make this using the &lt;i&gt;z-index&lt;/i&gt; property to hide the controls when it`s needed. &lt;br /&gt;First add the &lt;i&gt;z-index:-1;&lt;/i&gt; CSS property to the &lt;i&gt;slideshowcontrolsbg&lt;/i&gt; and &lt;i&gt;slideshowcontrols&lt;/i&gt; divs. This will hide the controls. Now we need to make it to reappear when the cursor is over the image. To do this we will create a function called &lt;i&gt;showcontrols&lt;/i&gt; what will set the z-index of the two divs to 1 and it will be triggered by the &lt;i&gt;onMouseOver&lt;/i&gt; even on &lt;i&gt;slideshow&lt;/i&gt; div. The funtion should look like this: &lt;div class="code"&gt;function showcontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = 1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = 1;&lt;br /&gt;}&lt;/div&gt;Now we just need an another function what will hide the controls when the cursor is moved away. I will name this function &lt;i&gt;hidecontrols&lt;/i&gt;, this will be very similar to the &lt;i&gt;showcontrols&lt;/i&gt; function, but this will set the z-index values to -1 and it will be triggered by the &lt;i&gt;onMouseOut&lt;/i&gt; event.&lt;br /&gt;&lt;br /&gt;After making all the changes my code look like this, your should look the same:&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;background:black;color:white;&amp;quot; &lt;span style="color:red;"&gt;onMouseOver=&amp;quot;showcontrols();&amp;quot; onMouseOut=&amp;quot;hidecontrols();&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;height:301px;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrolsbg&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;background:black;filter:alpha(opacity=60);opacity:0.6;z-index:-1;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   waitimage();&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      positioningimage();&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = 1;&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image').style.marginTop = (parseInt(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:red;"&gt;function showcontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = 1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = 1;&lt;br /&gt;}&lt;br /&gt;function hidecontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = -1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = -1;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;If you have any question don`t hesitate, ASK!&lt;br /&gt;Continue to &lt;a href="http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-5.html" title="Slideshow"&gt;part 5&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6665512325497740301?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9_samZ5oPt6eyDNZTvt3OmEtRz4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9_samZ5oPt6eyDNZTvt3OmEtRz4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9_samZ5oPt6eyDNZTvt3OmEtRz4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9_samZ5oPt6eyDNZTvt3OmEtRz4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/oUWFYzqy_cU" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">10</thr:total><feedburner:origLink>http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-4.html</feedburner:origLink></item><item><title>Creating a Javascript Slideshow part 3</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/CaWKImMupLM/creating-javascript-slideshow-part-3.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sat, 14 Aug 2010 13:21:22 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-3646341438513301688</guid><description>Before reading this read the &lt;a href="http://www.codingmix.com/2010/07/how-to-create-slideshow-without-jquery.html"&gt;first&lt;/a&gt; and &lt;a href="http://www.codingmix.com/2010/07/creating-javascript-slideshow-part-2.html"&gt;second&lt;/a&gt; parts of the tutorial.&lt;br /&gt;&lt;b&gt;Placing the image in the div&lt;/b&gt;&lt;br /&gt;In the previous part of the tutorial we had replaced the content of the &lt;i&gt;slideshowimage&lt;/i&gt; div with the value of &lt;i&gt;currentimage&lt;/i&gt;.&lt;div id="full-post"&gt;&lt;br /&gt;Now, we need to show the image with that number instead of the &lt;i&gt;currentimage&lt;/i&gt; number. This is very simple:&lt;br /&gt;In HTML an image look like this:&lt;div class="code"&gt;&amp;lt;img src=&amp;quot;image-url&amp;quot;/&amp;gt;&lt;/div&gt;And, we have an array of images, called &lt;i&gt;images&lt;/i&gt;, and we have the number of the image what needs to be displayed. So our image should look like: &lt;div class="code"&gt;&amp;lt;img src=&amp;quot;images[currentimage]&amp;quot;/&amp;gt;&lt;/div&gt;&lt;br /&gt;To do this, just replace &lt;div class="code"&gt;document.getElementById('slideshowimage').innerHTML = currentimage;&lt;/div&gt; with &lt;div class="code"&gt;document.getElementById('slideshowimage').innerHTML = '&amp;lt;img src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;/div&gt;Save your code, and see how it works. Well, it has some problems, the larger images are displayed only partially, &lt;i&gt;currentimage&lt;/i&gt; can be a higher the the number of images in the array, etc...  But, I will show you how to solve them, so  first let`s resize the images.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Resizing the images&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Using CSS we can set the width and height of an image, but if we set only the width the browser will calculate automatically the height to keep the aspect ratio. The width of our images needs to be the same as the width of the divs. I`we used 400px for the divs, so I could use 400px for the width of the images, but if I will add the Slideshow to my blog and I will need to resize the divs, I will need to edit the code, too. To avoid this we will use a simple Javascript property, &lt;i&gt;.style.width&lt;/i&gt;, which will check the width of the divs at each time the script starts.&lt;br /&gt;After editing it should look like this:&lt;div class="code"&gt;document.getElementById('slideshowimage').innerHTML = '&amp;lt;img width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;/div&gt;Save your code and notice how the images are resized. &lt;br /&gt;With one problem solved, let`s solve an another one, too:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;currentimage&lt;/i&gt; higher than the number of images&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If you have x images and you press the Next button x times, then the script will try to show the x+1 image or if you are at the first image and press the Prev button the the script will try to display the 0th image. &lt;br /&gt;Solving this is a very simple task. Each time the &lt;i&gt;showimage&lt;/i&gt; function starts we need to check if the value of &lt;i&gt;currentimage&lt;/i&gt; is &lt; 1 or &gt; then the existing images number before displaying the image. If &lt;i&gt;currentimage&lt;/i&gt; is smaller than 1, than we need to increase it to the number of existing images, if it`s bigger than the number of images we will need to decrease it to 1.&lt;br /&gt;To do this we need to know the number of images we have. The simplest way is to count them, but I will recommend the &lt;i&gt;.length&lt;/i&gt; property which will show the number of images + 1, so the real number of images will be that result number-1.&lt;br /&gt;Here is my code after editing it, your should look the same:&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Positioning the images&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Probably you have noticed that the height of the images is not the same, from this reason the &lt;i&gt;slideshowimage&lt;/i&gt; div has different sizes for each images and this moves down or up the &lt;i&gt;slideshowcontrols&lt;/i&gt; div and this is a problem and we need to solve it. &lt;br /&gt;First we need to set the height of the &lt;i&gt;slideshowimage&lt;/i&gt; div. I will use height:300px;, but you can use any value. This value will remain the same, it won`t change even if the image height is bigger. &lt;br /&gt;This solution seems good, but this brings some problems:&lt;br /&gt;- if the image height is bigger than the div`s height than only the top part of the image will be visible&lt;br /&gt;- if the image height is smaller, than the image will be placed on the top part of the div and the bottom of the div will be blank.&lt;br /&gt;With one solution we can solve both problems: centering the image in the div:&lt;br /&gt;- if the image is bigger than the center of the image will be shown&lt;br /&gt;- if the image is smaller than it will be shown in the center of the div&lt;br /&gt;&lt;br /&gt;I think this could be solved with some CSS tricks, but using only CSS can cause problems in some browser. To solve this we will need to use CSS but only the &lt;i&gt;margin&lt;/i&gt; property what is supported by almost all browsers. The &lt;i&gt;margin&lt;/i&gt; property sets the distance between two objects. In our case the distance between the image and the top of the &lt;i&gt;slideshowimage&lt;/i&gt; div.&lt;br /&gt;To do this we need to know exactly the distance required to center the images. This can be easily calculated:&lt;br /&gt;- Extract the height of the image from the height of the div (e.g: 400px - 360px or 400px - 420px) - this is the extra height &lt;br /&gt;- Divide the extra height with 2 (e.g: 40px/2 or -20px/2)&lt;br /&gt;- The result number is the needed distance (e.g: 20px or -10px) &lt;br /&gt;And, yes, the margin can be a negative number. &lt;br /&gt;&lt;br /&gt;Now, there`s an another problem, we need to know the height of the image (after it`s resized by the browser). The problem is that the height of an image can be get only after the image is loaded. We will get the height of the images using the &lt;i&gt;.height&lt;/i&gt; javascript property, which returns 0 or the height of the div in what is placed in if the image is not loaded completely, so we need to wait the image to load. &lt;br /&gt;&lt;br /&gt;We will check if the image is loaded using a function which will run until the image is loaded. Because we don`t want to freeze the computer we will delay the function by 250 milliseconds at each run. This means it will check the image 4 times a second. We will delay the function using the &lt;i&gt;setTimeout&lt;/i&gt; property.&lt;br /&gt;&lt;br /&gt;To get the height of an image we need the id of that image, so we need to add an id to each image. The id can be the same for all images because the images are not displayed at the same time: I will use the id &lt;i&gt;image&lt;/i&gt;. &lt;br /&gt;To do this just edit the line what changes the content of the &lt;i&gt;slideshowimage&lt;/i&gt; div in the following way: &lt;div class="code"&gt;document.getElementById('slideshowimage').innerHTML = '&amp;lt;img &lt;span style="color:red;"&gt;id=&amp;quot;image&amp;quot;&lt;/span&gt; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;/div&gt;&lt;br /&gt;After editing the above line let`s create the function (call it &lt;i&gt;waitimage&lt;/i&gt;)what waits the images to load. We will check if the image is loaded or not using the &lt;i&gt;.complete&lt;/i&gt; property. To test it first just alert the height of the images.&lt;div class="code"&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      alert(document.getElementById('image').height);&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;/div&gt;Don`t forget to start the above function from the end of &lt;i&gt;showimage&lt;/i&gt; function.&lt;br /&gt;&lt;br /&gt;Now, we have all the data to place the images in position. We just need to create a function (call it positioningimage) what will be triggered when the image is loaded and will calculate space needed between the image and the top of the div to center it. &lt;br /&gt;NOTE: When you are getting the height of a div using .style.height the result is a string like 400px not a number like 400. To get a number use the &lt;i&gt;parseInt()&lt;/i&gt; function.&lt;br /&gt;Here is my code after adding all these things to it. Your code should look the same:&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;&lt;span style="color:red;"&gt;height:300px;&lt;/span&gt;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   &lt;span style="color:red;"&gt;waitimage();&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image')&lt;span style="color:red;"&gt;.complete&lt;/span&gt;){&lt;br /&gt;     &lt;span style="color:red;"&gt; positioningimage();&lt;/span&gt;&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:red;"&gt;setTimeout('waitimage()',250);&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image')&lt;span style="color:red;"&gt;.style.marginTop&lt;/span&gt; = (&lt;span style="color:red;"&gt;parseInt&lt;/span&gt;(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;Test it out with different div heights.&lt;br /&gt;&lt;br /&gt;Sorry, I know that this part of the tutorial was harder. I recommend you to read it multiple times and if you have any question than don`t be afraid to ASK! I have highlighted the most important changes for a better understanding. &lt;br /&gt;&lt;br /&gt;Continue to &lt;a href="http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-4.html" title="slideshow"&gt;Part 4&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-3646341438513301688?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DnnuvzaPV7PcM86oPqfgyDHNuXg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DnnuvzaPV7PcM86oPqfgyDHNuXg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DnnuvzaPV7PcM86oPqfgyDHNuXg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DnnuvzaPV7PcM86oPqfgyDHNuXg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/CaWKImMupLM" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/07/creating-javascript-slideshow-part-3.html</feedburner:origLink></item><item><title>Creating a Javascript Slideshow part 2</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/8j82fdfptUc/creating-javascript-slideshow-part-2.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 30 Jul 2010 04:04:02 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-3332053879853969216</guid><description>Before reading this read the &lt;a href="http://www.codingmix.com/2010/07/how-to-create-slideshow-without-jquery.html" title="Creating a Javascript Slideshow"&gt;first part&lt;/a&gt;. Now, let`s continue:&lt;br /&gt;&lt;b&gt;Add the images&lt;/b&gt;&lt;br /&gt;The images URL will be stored in an array, you can use any number of images. I will name this array images, and I will add 5 images to it:&lt;div id="full-post"&gt;&lt;div class="code"&gt;var images = new Array;&lt;br /&gt;images[1] = "http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg";&lt;br /&gt;images[2] = "http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg";&lt;br /&gt;images[3] = "http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg";&lt;br /&gt;images[4] = "http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg";&lt;br /&gt;images[5] = "http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg";&lt;/div&gt;Note: The images will be displayed in the order you add them to the array.&lt;br /&gt;Note: Place the array before the &lt;i&gt;changeimage&lt;/i&gt; function.&lt;br /&gt;The images can have any size.&lt;br /&gt;&lt;br /&gt;Now we need to create a variable what will hold the number of the current image, with initial value of 1, because the first image will be the one with the index 1. Name this variable &lt;i&gt;currentimage&lt;/i&gt;&lt;div class="code"&gt;var currentimage = 1;&lt;/div&gt;Place the variable before the &lt;i&gt;changeimage&lt;/i&gt; function.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Changing the images&lt;/b&gt;&lt;br /&gt;Now begins the real fun :D. The concept is simple: Always the image with the number equal to &lt;i&gt;currentnumber&lt;/i&gt; will be shown. When the Next button is pressed the value of &lt;i&gt;currentimage&lt;/i&gt; will be increased by 1, or decreased if Prev is pressed.&lt;br /&gt;I will do this by simple adding a parameter (named &lt;i&gt;change&lt;/i&gt;) to the &lt;i&gt;changeimage&lt;/i&gt; function. The prev button`s parameter will be -1 and the next`s parameter will be 1, and the parameter value will be added to &lt;i&gt;currentimage&lt;/i&gt;. First to test the code, change the &lt;i&gt;alert("ok");&lt;/i&gt; to &lt;i&gt;alert(change);&lt;/i&gt;&lt;img style="display:block; margin:0px auto 10px;width: 467px; height: 372px;" src="http://2.bp.blogspot.com/_Ok7mVUxPcsk/TE9AngRm0RI/AAAAAAAAAQE/ZLPbj2Nni0M/s1600/Slideshow+concept.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5498684717465522450" /&gt;After the above changes my code look like this, your code should look the same:&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;function changeimage(change){&lt;br /&gt;   alert(change);&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;The above code should alert -1 if you press Prev and 1 if you press Next&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Changing &lt;i&gt;currentimage&lt;/i&gt; value&lt;/b&gt;&lt;br /&gt;Now, remove the &lt;i&gt;alert(change);&lt;/i&gt; line from the function and instead add the following lines:&lt;div class="code"&gt;currentimage += change;&lt;br /&gt;alert(currentimage);&lt;/div&gt;This is very simple, first the value of &lt;i&gt;currentimage&lt;/i&gt; is increased by -1 or 1 and then the final value is alerted.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Display the images&lt;/b&gt;&lt;br /&gt;Now, that we have the number of the image to show, we need only to display them.&lt;br /&gt;This can be easily done by using the innerHTML property, which can replace the content of a div with whatever you want. First to test it, replace the &lt;i&gt;alert(currentimage);&lt;/i&gt; line from your code with the following one:&lt;div class="code"&gt;document.getElementById('slideshowimage').innerHTML = currentimage;&lt;/div&gt;How it works: This line will search for an element with the id&lt;br /&gt;&lt;i&gt;slideshowimage&lt;/i&gt;, and it will replace it`s content with the value of &lt;i&gt;currentimage&lt;/i&gt;&lt;br /&gt;Now, you code will not alert the current image number, it will write it inside the &lt;i&gt;slideshowimage&lt;/i&gt; div.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Starting the function to show the first image, too&lt;/b&gt;&lt;br /&gt;Probably you have noticed that the current image number is displayed only after a button is pressed. This is because the function which writes the number starts only at the push of a button. To solve this we need to start the function immediately after the page is loaded. &lt;br /&gt;To do this place the following line after the &lt;i&gt;changeimage&lt;/i&gt; function (after } ):&lt;div class="code"&gt;changeimage(0);&lt;/div&gt;Notice that the parameter is 0, so this will not increase the value of &lt;i&gt;currentimage&lt;/i&gt; to start from image 1&lt;br /&gt;&lt;br /&gt;Now my code look like this (your should look the same):&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = currentimage;&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;a href="http://www.codingmix.com/2010/07/creating-javascript-slideshow-part-3.html"&gt;Continue to the third part of the tutorial.&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-3332053879853969216?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MFgYLy0qQ8vgSV7_7WZSOR5eMlU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MFgYLy0qQ8vgSV7_7WZSOR5eMlU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MFgYLy0qQ8vgSV7_7WZSOR5eMlU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MFgYLy0qQ8vgSV7_7WZSOR5eMlU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/8j82fdfptUc" height="1" width="1"/&gt;</description><media:thumbnail url="http://2.bp.blogspot.com/_Ok7mVUxPcsk/TE9AngRm0RI/AAAAAAAAAQE/ZLPbj2Nni0M/s72-c/Slideshow+concept.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.codingmix.com/2010/07/creating-javascript-slideshow-part-2.html</feedburner:origLink></item><item><title>How to create a Slideshow without jQuery, just Javascript and HTML</title><link>http://feedproxy.google.com/~r/codingmix/Javascript/Tutorials/~3/J0xiRHrcvjw/how-to-create-slideshow-without-jquery.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 29 Aug 2010 05:40:07 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-4224506499980637021</guid><description>In this tutorial I will show you how to create a simple but effective Slideshow using only HTML, CSS and Javascript. The concept of this slideshow is simple: to change the image the content of a div will be changed using innerHTML. But, this is far enough for now, because I want to write this tutorial to be understood by everybody, with or without previous experience in Javascript. &lt;br /&gt;&lt;div id="full-post"&gt;&lt;br /&gt;Now, you probably ask "Where I need to write the code?" - Well you can write it in any HTML editor like Adobe Dreamweaver or you can write it simply in Notepad (this is what I will describe in this tutorial), because HTML and Javascript don`t require a compiler like C++.&lt;br /&gt;Just open &lt;b&gt;Notepad&lt;/b&gt; and write the following code in a blank file: &lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!-- Code goes here --&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;Now click on &lt;b&gt;File&lt;/b&gt; &gt;&gt; &lt;b&gt;Save as...&lt;/b&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 530px; height: 427px;" src="http://2.bp.blogspot.com/_Ok7mVUxPcsk/TE7rmvhnBAI/AAAAAAAAAP8/s7CGT9pfGS8/s1600/Notepad+HTML+file.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5498591245890946050" /&gt;At the file name type in any name, but end it with &lt;b&gt;.html&lt;/b&gt;, (e.g.: slideshow.html), and at Save as type select &lt;b&gt;All files&lt;/b&gt;&lt;br /&gt;To preview your page just open your file in a browser like Firefox or Internet Explorer - it should be a blank page. &lt;br /&gt;It`s useful to preview you code from time to time, because if you get an error at the end you will need to recheck the whole code.&lt;br /&gt;&lt;br /&gt;Now, you can remove the &amp;lt;!-- Code goes here --&amp;gt; line, just remember that the code needs to be placed between the &amp;lt;body&amp;gt; and &amp;lt;/body&amp;gt; tags.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Creating the div`s&lt;/b&gt;&lt;br /&gt;We need 3 div`s (a div is like and invisible box):&lt;br /&gt;- one to hold the entire slideshow (the following 2 div`s) - call it &lt;i&gt;slideshow&lt;/i&gt; (id="slideshow")&lt;br /&gt;- another one to hold the images (one at a time) - &lt;i&gt;slideshowimage&lt;/i&gt;&lt;br /&gt;- and one to hold the control buttons (next, prev...) - &lt;i&gt;slideshowcontrols&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Note: All of these divs will have fixed width, I will use 400px, but you can use any size, because the script will detect any size, but make sure that you use the same width for all of them!&lt;br /&gt;Use for all of the divs the overflow:hidden; option. &lt;br /&gt;I recommend to use inline CSS (using the style="" tag)&lt;br /&gt;Here is my code:&lt;div class="code"&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Start working with Javascript&lt;/b&gt;&lt;br /&gt;Write the following code bellow the above code (before &amp;lt;/body&amp;gt;):&lt;div class="code"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;These are the starting and the ending tags of Javascript.&lt;br /&gt;&lt;br /&gt;Now create between those tags function called &lt;i&gt;changeimage&lt;/i&gt; and inside alert "ok":&lt;br /&gt;&lt;div class="code"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function changeimage(){&lt;br /&gt;   alert("ok");&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;Now we need something to trigger the function. The images will change on pressing a button: Prev, Next or by clicking the image, so first let`s add the two buttons to the slideshowcontrols div:&lt;br /&gt;I will use a tags with onclick event: &lt;div class="code"&gt;&amp;lt;a onclick=&amp;quot;changeimage();&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onclick=&amp;quot;changeimage();&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;/div&gt;Save your file and click on one of the buttons - it should alert "ok".&lt;br /&gt;If you have followed with attention each step your code should look like this:&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onclick=&amp;quot;changeimage();&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onclick=&amp;quot;changeimage();&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function changeimage(){&lt;br /&gt;   alert(&amp;quot;ok&amp;quot;);&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;a href="http://www.codingmix.com/2010/07/creating-javascript-slideshow-part-2.html" title="Slideshow"&gt;Continue to the second part of the tutorial&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-4224506499980637021?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ciTi4n8zf_o9o5hD4sA6w-Wgf6o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ciTi4n8zf_o9o5hD4sA6w-Wgf6o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ciTi4n8zf_o9o5hD4sA6w-Wgf6o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ciTi4n8zf_o9o5hD4sA6w-Wgf6o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Javascript/Tutorials/~4/J0xiRHrcvjw" height="1" width="1"/&gt;</description><media:thumbnail url="http://2.bp.blogspot.com/_Ok7mVUxPcsk/TE7rmvhnBAI/AAAAAAAAAP8/s7CGT9pfGS8/s72-c/Notepad+HTML+file.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/07/how-to-create-slideshow-without-jquery.html</feedburner:origLink></item><media:rating>nonadult</media:rating></channel></rss>

