Bonjour les amis,

Je suis débutant en Javascript. J'ai un code diaporama qui marche vraiment nickel. Les images sont dans un tableau
randImgObj.set1 = new Array("photo1.jpg", "photo2.jpg");
Je voudrais assigné à chaque image un titre et un lien sur le titre.
Comme ça. l'image qui s'affiche à son titre en dessous et ce titre est un lien

Comment déclarer ce tableau?
Comment afficher l'image avec son titre/lien

Je vous remercie d'avance pour votre aide

Voici le code. (Il marche nickel. Ce n'est pas le problème)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
//LE CODE JAVASCRIPT QUI TRAITE L'IMAGE
<SCRIPT language=JavaScript type=text/javascript>
 
// image file names go in these arrays
randImgObj.set1 = new Array("photo1.jpg", "photo2.jpg");
 
 
// If all the images you wish to display are in the same location, you can specify the path here 
randImgObj.imagesPath = "images/";
 
// No need to edit code below this line 
/////////////////////////////////////////////////////////////////////
Array.prototype.shuffle = function() { 
  var i, temp, i1, i2;
  for (i=0; i<this.length; i++) { 
    i1 = Math.floor( Math.random() * this.length );
    i2 = Math.floor( Math.random() * this.length );
    temp = this[i1];
    this[i1] = this[i2];
    this[i2] = temp;
  }
}
 
randImgObjs = []; // holds all random rotating image objects defined
// constructor 
function randImgObj(s) {
  this.speed=s; this.ctr=0; this.timer=0;  
  this.index = randImgObjs.length; randImgObjs[this.index] = this;
  this.animString = "randImgObjs[" + this.index + "]";
}
 
randImgObj.prototype = {
  addImages: function(ar) { // preloads images
    this.imgObj.imgs = [];
    for (var i=0; ar[i]; i++) {
      this.imgObj.imgs[i] = new Image();
      this.imgObj.imgs[i].src = randImgObj.imagesPath + ar[i];
    }
  },
 
  rotate: function() { // controls rotation
    var ctr = Math.floor( Math.random() * this.imgObj.imgs.length );
    if (ctr == this.ctr) ctr = (ctr > 0)? --ctr: ++ctr;
    this.ctr = ctr;
    if ( typeof this.imgObj.filters != "undefined" ) {
   		this.imgObj.style.filter = 'blendTrans(duration=1)';
      if (this.imgObj.filters.blendTrans) this.imgObj.filters.blendTrans.Apply();
    }
    this.imgObj.src = this.imgObj.imgs[this.ctr].src;
    if ( typeof this.imgObj.filters != "undefined" && this.imgObj.filters.blendTrans )
      this.imgObj.filters.blendTrans.Play();    
  }
}
 
// sets up rotation for all defined randImgObjs
randImgObj.start = function() {
  for (var i=0; i<randImgObjs.length; i++) 
    randImgObjs[i].timer = setInterval(randImgObjs[i].animString + ".rotate()", randImgObjs[i].speed);                     
}
 
randImgObj.setUpImg = function(imgAr, sp, w, h) {
  var rotator, img, imgStr = "";
  rotator = new randImgObj(sp);
  randImgObjs[randImgObjs.length-1].imgAr = imgAr;
  imgAr.shuffle();
  img = imgAr[ Math.floor( Math.random() * imgAr.length ) ]; 
  imgStr += '<img src="' + randImgObj.imagesPath + img + '" alt="" ';
  imgStr += 'name="img' + (randImgObjs.length-1) + '" width="' + w + '" height="' + h + '">';
  document.write(imgStr); 
}
 
function initRandRotation() {
  for (var i=0; randImgObjs[i]; i++) {
    var rotator = randImgObjs[i];
    rotator.imgObj = document.images["img" + i]; // get reference to the image object
    rotator.addImages(rotator.imgAr);
    rotator.rotate();
  }
  randImgObj.start();  
}
 
//-->
</SCRIPT>
 
<STYLE type=text/css>BODY {
	MARGIN: 0px
}
</STYLE>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
//LE CODE HTML ET JAVASCRIPT QUI AFFICHE L'IMAGE
<BODY onload=initRandRotation();>
<table width="474" height="174" border="0">
  <!--DWLayoutTable-->
  <tr> 
    <td width="468"><SCRIPT type=text/javascript>
//  images array, delay, width and height of images
randImgObj.setUpImg(randImgObj.set1, 4600, 474, 174);
</SCRIPT>&nbsp;</td>
  </tr>
</table>
</BODY>
Merci d'avance pour aide