Difference between revisions of "Image slider"

From Organic Design wiki
m
m
Line 15: Line 15:
 
{{code|1=<xml><!DOCTYPE html>
 
{{code|1=<xml><!DOCTYPE html>
 
<html lang="en">
 
<html lang="en">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <head>
+
  <head>
    <title>Image Slider</title>
+
      <title>Image Slider</title>
    <script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
+
      <script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script src="http://svn.organicdesign.co.nz/dl.php?repname=extensions&path=%2FImageSlider.js" type="text/javascript"></script>
+
      <script src="http://svn.organicdesign.co.nz/dl.php?repname=extensions&path=%2FImageSlider.js" type="text/javascript"></script>
  </head>
+
  </head>
  <body>
+
  <body>
    <div class="image-slider thumbs">
+
      <div class="image-slider thumbs">
      <img src="http://www.organicdesign.co.nz/files/thumb/1/12/Yellow_caterpillar_with_red_face.jpg/500px-Yellow_caterpillar_with_red_face.jpg" />
+
        <img src="http://www.organicdesign.co.nz/files/thumb/1/12/Yellow_caterpillar_with_red_face.jpg/500px-Yellow_caterpillar_with_red_face.jpg" />
      <img src="http://www.organicdesign.co.nz/files/thumb/f/f2/Red_hairy_caterpillar.jpg/500px-Red_hairy_caterpillar.jpg" />
+
        <img src="http://www.organicdesign.co.nz/files/thumb/f/f2/Red_hairy_caterpillar.jpg/500px-Red_hairy_caterpillar.jpg" />
      <img src="http://www.organicdesign.co.nz/files/thumb/1/17/Green_and_red_caterpillar_2.jpg/500px-Green_and_red_caterpillar_2.jpg" />
+
        <img src="http://www.organicdesign.co.nz/files/thumb/1/17/Green_and_red_caterpillar_2.jpg/500px-Green_and_red_caterpillar_2.jpg" />
      <img src="http://www.organicdesign.co.nz/files/thumb/1/13/Black_caterpillar_with_yellow_stripes_1.jpg/500px-Black_caterpillar_with_yellow_stripes_1.jpg" />
+
        <img src="http://www.organicdesign.co.nz/files/thumb/1/13/Black_caterpillar_with_yellow_stripes_1.jpg/500px-Black_caterpillar_with_yellow_stripes_1.jpg" />
      <img src="http://www.organicdesign.co.nz/files/thumb/3/39/Yellow_hairy_caterpillar_2.jpg/500px-Yellow_hairy_caterpillar_2.jpg" />
+
        <img src="http://www.organicdesign.co.nz/files/thumb/3/39/Yellow_hairy_caterpillar_2.jpg/500px-Yellow_hairy_caterpillar_2.jpg" />
    </div>
+
      </div>
  </body>
+
  </body>
 
</html></xml>}}
 
</html></xml>}}
  

Revision as of 19:14, 31 March 2015

Here's a simple image slider written 100% in JavaScript and jQuery. In converts any div elements of class "image-slider" containing img elements into a slider like the one below. You can use your own CSS rules to give the next/prev links a nicer style and make a frame around the image. The images should all be the same size for it to work properly. The code is in our Subversion repository here.

There are two variables at the start of the code, delay and thumbWidth, these determine the time in seconds before the next image change, and the width in pixels of the thumbnail images below the sliding image. Each image slider div element can be configured to have a row of clickable thumbnail images below the sliding image by adding "thumbs" to the class attribute as in the example code following.

In the wiki you can use image links as follows:

<xml>
   Butterfly3.jpg
   YellowButterfly.jpg
   MonarchOnPinkTree3.jpg
   Butterfly1.jpg
</xml>


Here's an example of a pure HTML page which has the links to the scripts and images included:

<xml><!DOCTYPE html>

Image Slider

</xml>


Here's a working example:

Butterfly3.jpg Ethilla Longwing 1.jpg Butterfly1.jpg Blue butterfly on chia.jpg 2015 red butterfly 2.jpg