JavaScript Picture Slider

Hello,

I was coding this little Picture Slider in JavaScript for a colleague and thought: Why not just share it with everybody else?

So here it is people… It is not advanced, it is not high-tech… but it is simple!

  1. <html>
  2.  
  3. <head>
  4.     <title>Picture Slider</title>
  5.  
  6.     <script type="text/javascript">
  7.     // Setup
  8.     var imagePath = "images/"; // Path to image-folder
  9.     var images = new Array("image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg"); // filenames of the images
  10.     var slideInterval = 1.5; // amount of seconds before sliding to the next image.
  11.  
  12.    // Variabels
  13.     var curImage = 0;
  14.  
  15.     // Fucntions   
  16.     function startSlide() {
  17.         setTimeout("nextSlide()", slideInterval * 1000);
  18.     }
  19.  
  20.     function nextSlide() {
  21.         var viewer = document.getElementById("imageViewer");
  22.         curImage = curImage + 1;
  23.  
  24.         if (images[curImage] == null)
  25.             curImage = 0;
  26.  
  27.         viewer.src = imagePath + images[curImage];
  28.  
  29.         setTimeout("nextSlide()", slideInterval * 1000);
  30.     }
  31.  
  32.     // Start the slider
  33.     startSlide();
  34.     </script>
  35. </head>
  36.  
  37. <body>
  38.  
  39.     <h1>Picture Slider</h1>
  40.     <br />
  41.     <img id="imageViewer" src="images/image1.jpg">
  42.  
  43. </body>
  44.  
  45. </html>

Just change the variables under the “setup” in the start of the JavaScript-code and change the src-parameter on the img-tag of the picture to show the first picture. Then the script will work.

Have fun !!

/KEF

VBScript – Choosing an editor

This will be my first article about coding in VBScript. I have not done it before, so I will on my blog write down my problems, the solutions to them and my thoughts about VBScript.

This series of articles will be written in English, so please forgive any misspelling etc.

Choosing an editor
Since I have no experience in coding in VBScript, I neither have any idea about which editor is good or bad. I made a simple search on Google with the keywords “vbs editor” and choose the first (and hopefully the best) editor on the result list.

The editor I found is called VbsEdit and it is an award-winning editor. The editor is still begin updated – I downloaded the last version released December 19, 2008. The version is 3.4.1.

You can download the file by clicking here (to download from my mirror, click here). If you want to read more about VbsEdit you can go to http://www.vbsedit.com/.

The editor should containt a debugger, so I can test my script directly from the program, syntax highlighting, line numbers, code snippets, code samples, displaying of methods etc. when writing the code and other cool stuff like that.

The editor is a evaluation version, but this version never expires, so you do not need to register the product. However if you feel like doing it, it costs 49,00 USD for a single-user lifetime license, so the editor is not very expensive. I have desided to test the editor first to see if its the right editor for me.

As I said before this is the first article in a series of articles about VBScript. I will later on write about my first thoughts, problems and such when starting to code in VBS.

Until that happens – have a nice time !