Voici une lightbox / diaporama version lite
démo en ligne v1:

http://easynews.free.fr/diapoFluide/

voici la v2 :

http://easynews.free.fr/mbox/


code de la V2 :

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Démo calendrier v2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
    body,html{
        margin:0px;
        padding:0px;
        width:100%;
        height:100%;
    }
    .beforeOut{
        width:27px;
        height:25px;
        background:url('images/navigate.png') 0px 0px;
        float:left;
    }
    .beforeOutOver{
        width:27px;
        height:25px;
        background:url('images/navigate.png') 0px -25px;
        float:left;
    }
 
    .beforeOutClick{
        width:27px;
        height:25px;
        background:url('images/navigate.png') 0px -50px;
        float:left;
    }
    .nextOut{
        width:27px;
        height:25px;
        background:url('images/navigate.png') -27px 0px;
        float:left;
    }
    .nextOutOver{
        width:27px;
        height:25px;
        background:url('images/navigate.png') -27px -25px;
        float:left;
    }
 
    .nextOutClick{
        width:27px;
        height:25px;
        background:url('images/navigate.png') -27px -50px;
        float:left;
    }
    .close{
        width:27px;
        height:25px;
        position:absolute;
        right:20px;
        top:4px;
        background:url('images/navigate.png') 0px -131px;
    }
    .indicator{
        height:25px;
        padding-left:10px;
        padding-right:10px;
        line-height:25px;
        text-align:center;
        color:#666;
        font-weight:bold;
        float:left;
        background:url('images/navigate.png') 0px -108px;
    }
    .toolbar{
        width:120px;
        position:absolute;
        top:5px;
        left:50%;
        margin-left:-60px;
        clear:both;
    }
    .navigate{
        width:100%;
        height:33px;
        line-height:33px;
        background:url('images/navigate.png') 0px -75px;
        position: fixed;
        top:10px;
        left:0px;
        /* et le patch pour IE */ 
      position : expression("absolute"); 
      width : expression("100%"); 
      top : expression(document.body.scrollTop + this.offsetHeight - this.offsetHeight); 
      left : expression("0px"); 
 
    }
    .imageInformation{
        color:#666;
        font-weight:bold;
        float:left;
        margin-left:20px;
    }
    .modal{
        width:100%;
        height:100%;
        top:0px;
        left:0px;
        background-color:#000;
        position:absolute;
        filter:alpha(opacity=70);
        -moz-opacity:.7;
        opacity:.7;
    }
    .frameBugFlash{
        position:absolute;
        top:0px;
        left:0px;
        z-index:0;
        width:100%;
        height:100%;
        border:0px;
        filter:alpha(opacity=0);
        -moz-opacity:.0;
        opacity:.0;
    }
    .contentMain{
        width:100%;
        height:100%;
        top:0px;
        left:0px;
        position: fixed;
        /* et le patch pour IE */ 
          position : expression("absolute"); 
          width : expression("100%"); 
          top : expression(document.body.scrollTop + this.offsetHeight - this.offsetHeight); 
          left : expression("0px"); 
 
    }
    .contentImage{
        border:3px solid #666;
        background-color:#FFFFFF;
        position:absolute;
        padding:10px;
    }
    .imgHide{
        filter:alpha(opacity=0);
        -moz-opacity:.0;
        opacity:.0;
    }
</style>
 
<script type="text/javascript">
function mBox(conteneurImage,activatePreload){
    //Les objets composant la barre de navigation
    this.navigate = null;
    this.toolbar = null;
    this.next =  null;
    this.before = null ;
    this.close = null ;
    this.indicator = null;
    this.imageInformation = null;
    //La div + frame modale
    this.contentMain = null;
    this.contentImage = null;
    this.frameBugFlash = null;
    //Le tableau contenant toutes les images
    this.arrayImage = new Array();
    //Objet image courante
    this.imgCurrent = null;
    this.indexCurrent = 0 ;
 
    //Un timer pour l'effet de fading et un autre pour l'aggrandissement de la boite
    this.timer = null;
    this.timer2 = null;
 
    this.x = 0;
    this.y = 0 ;
    this.largeur = 0 ;
    this.hauteur = 0;
 
    this.imgCurrent = null;
    this.maxH = 0 ;
    this.maxL = 0 ;
    this.IsIE=!!document.all;
    this.upL = false;
    this.upH = false;
    this.verifH = false;
    this.verifL = false;
    this.conteneur = conteneurImage;
    this.css = null ;
    this.imgLoader = null;
    this.spanInfo = null; 
    this.divError =  null; 
    //Variable permettant ou non d'activer le preload
    this.preload = (typeof(activatePreload)  != 'undefined') ? activatePreload:false;
    //On initialise :)
    this.init();
}
 
mBox.prototype.init = function(){
    //récupération de toutes les images du conteneur et de la balise alt
    this.getAllImage();
    //Ajout de la frame pour passer au dessus des flash + le conteneur transparent
    this.contentMain = this.newElement({"typeElement":"div","classeCss":"contentMain","parent":null});
    this.frameBugFlash = this.newElement({"typeElement":"div","classeCss":"modal","parent":this.contentMain});
    this.newElement({"typeElement":"iframe","classeCss":"frameBugFlash","parent":this.contentMain });
    //Ajout du conteneur de l'image
    this.contentImage = this.newElement({"typeElement":"div","classeCss":"contentImage","parent":this.contentMain});    
    this.css = this.contentImage.style;
    //Construction de la barre de navigation
    this.navigate = this.newElement({"typeElement":"div","classeCss":"navigate","parent":null});
    this.imageInformation = this.newElement({"typeElement":"div","classeCss":"imageInformation","parent":this.navigate});
    this.toolbar = this.newElement({"typeElement":"div","classeCss":"toolbar","parent":this.navigate});
    this.before = this.newElement({"typeElement":"div","classeCss":"beforeOut","parent":this.toolbar});
    var me = this;
    this.before.onclick = function(){me.beforeImg()};
    this.indicator = this.newElement({"typeElement":"div","classeCss":"indicator","parent":this.toolbar});
    this.next = this.newElement({"typeElement":"div","classeCss":"nextOut","parent":this.toolbar});
    this.next.onclick = function(){me.nextImg()};
    this.close = this.newElement({"typeElement":"div","classeCss":"close","parent":this.navigate});
    this.close.onclick = function(){me.hide([me.contentMain,me.navigate])};
    //Création de l'image de load
    this.imgLoader = this.newElement({"typeElement":"img","classeCss":"","parent":this.contentImage});
    this.imgLoader.src = "images/loader.gif";
 
    //On masque les éléments principaux
    this.hide([this.navigate,this.contentMain,this.imgLoader]);
}
 
mBox.prototype.show = function(element){
    if(element instanceof Array){
        for(var i = 0 , l = element.length ; i <l ; i++){
            element[i].style.display = "block";
        }
    }
    else{
        element.style.display = "block";
    }
}
 
mBox.prototype.hide = function(element){
    if(element instanceof Array){
        for(var i = 0 , l = element.length ; i <l ; i++){
            element[i].style.display = "none";
        }
    }
    else{
        element.style.display = "none";
    }
}
 
mBox.prototype.seeCurent = function(numCurrent)
{
    //Index de l'image courante
    this.indexCurrent = numCurrent;
    //On tue les anciens timers
    clearTimeout(this.timer);
    clearTimeout(this.timer2);
    //On supprimer l'ancienne image
        this.removeImg();
        this.show([this.navigate,this.contentMain]);
        //On ajoute la nouvelle
        this.createImg(this.arrayImage[this.indexCurrent]);
        this.seeCurentPosition();
}
 
mBox.prototype.nextImg = function()
    {
      if(this.indexCurrent < (this.arrayImage.length-1)){this.indexCurrent++;}else{this.indexCurrent=0;}
 
      clearTimeout(this.timer);
      clearTimeout(this.timer2);
      this.removeImg();
      this.createImg(this.arrayImage[this.indexCurrent]);
      this.seeCurentPosition();
    }
 
    mBox.prototype.beforeImg = function()
    {
      if(this.indexCurrent > 0){this.indexCurrent--;}else{this.indexCurrent=(this.arrayImage.length-1);}
 
      clearTimeout(this.timer);
      clearTimeout(this.timer2);
      this.removeImg();
      this.createImg(this.arrayImage[this.indexCurrent]);
      this.seeCurentPosition();
    }
 
mBox.prototype.createImg = function(iSrc)
{
    var me =  this ;
    this.imgCurrent = document.createElement('img')
    this.imgCurrent.className = "imgHide";    
    this.imgCurrent.onerror = function(){me.MsgErreurShow();};
    this.imgCurrent.src = iSrc;
    this.imgCurrent.style.visibility = "hidden";
    this.imgCurrent.id = "imgCurrent";
    this.verifLoadImg();
}
 
mBox.prototype.removeImg = function()
{
      if(this.imgCurrent!=null){
        this.contentImage.removeChild(this.imgCurrent);
    }
}
 
mBox.prototype.verifLoadImg = function() 
    {
 
      var temp = this ;
       if(this.imgCurrent.complete)
      {
          if(this.imgCurrent.width != 0){
            //On masque le message d'erreur et l'image de loading
            this.hide(this.imgLoader);
            //On tue le timer
            clearTimeout(this.timer);
            //Récupération de la taille de l'écran 
            result=this.returnSize();
 
            var myWidth=result[0];
            var myHeight=result[1];
            //test si l'image est plus grande en largeur ou hauteur :
            if(myWidth < (this.imgCurrent.width+100) || myHeight < (this.imgCurrent.height+100)){
                //On va récupérer les nouvelles valeur
                var MaxSize = this.getMaxSizeDisplay(parseInt(myWidth/100*60),parseInt(myHeight/100*60));
                this.maxL = MaxSize[0] + 20;
                this.maxH = MaxSize[1] + 20;
            }
            else{
                this.maxL = this.imgCurrent.width + 20;
                this.maxH = this.imgCurrent.height + 20;
            }
            this.upL = (this.largeur <= this.maxL) ? true:false;
            this.upH = (this.hauteur <= this.maxH) ? true:false;
            this.verifH = false;
            this.verifL = false;
            this.openBox();
        }
      }
      else
      {
      this.show(this.imgLoader);
        this.imgLoader.style.position = "absolute";
      this.imgLoader.style.top = "50%";
      this.imgLoader.style.left = "50%";
        this.imgLoader.style.marginLeft = -(parseInt(this.imgLoader.offsetWidth)/2) +"px" ;
        this.imgLoader.style.marginTop =- (parseInt(this.imgLoader.offsetHeight) /2) +"px";
        var temp = this;
        this.timer = setTimeout(function() {temp.verifLoadImg();}, 500);
      }
    }
 
mBox.prototype.getMaxSizeDisplay = function(inMW, inMH)
{
    // inMW  : Largeur maximale
    // inMH   : Hauteur maximale
    var maxWidth = inMW;
    var maxHeight = inMH;
    // Declarations des variables "Nouvelle Taille"
    var dW = 0;
    var dH = 0;
    // On recupere les tailles reelles
    var h = dH = this.imgCurrent.height;
    var w = dW = this.imgCurrent.width;
    // Si la largeur ou la hauteur depasse la taille maximale
    if ((h >= maxHeight) || (w >= maxWidth)) {
    // Si la largeur et la hauteur depasse la taille maximale
    if ((h >= maxHeight) && (w >= maxWidth)) {
      // On cherche la plus grande valeur
      if (h > w) {
        dH = maxHeight;
        // On recalcule la taille proportionnellement
        dW = parseInt((w * dH) / h, 10);
      } else {
        dW = maxWidth;
        // On recalcule la taille proportionnellement
        dH = parseInt((h * dW) / w, 10);
      }
    } else if ((h > maxHeight) && (w < maxWidth)) {
      // Si la hauteur depasse la taille maximale
      dH = maxHeight;
        // On recalcule la taille proportionnellement
      dW = parseInt((w * dH) / h, 10);
    } else if ((h < maxHeight) && (w > maxWidth)) {
      // Si la largeur depasse la taille maximale
      dW = maxWidth;
        // On recalcule la taille proportionnellement
      dH = parseInt((h * dW) / w, 10);
    }
    }
    return new Array(dW,dH)
}
 
//Récupération de la taille de l'écran
mBox.prototype.returnSize = function()
{
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) 
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    var result = new Array(myWidth,myHeight);
    return result;
}
 
mBox.prototype.openBox = function()
    {
      this.windowCenter(this.contentImage);
      if(this.largeur < this.maxL && this.upL)
      {
        this.largeur += 20 ;
        this.css.width = this.largeur + "px";
      }
      else if(this.largeur > this.maxL && !this.upL)
      {
        this.largeur -= 20 ;
        this.css.width = this.largeur + "px";
      }
      else
      {
        this.verifL = true;
      }
      if(this.hauteur < this.maxH && this.upH)
      {
        this.hauteur += 20 ;
        this.css.height = this.hauteur + "px";
      }
      else if(this.hauteur > this.maxH && !this.upH)
      {
        this.hauteur -= 20 ;
        this.css.height = this.hauteur + "px";
      }
      else
      {
        this.verifH = true;
        }
 
      if(this.verifH && this.verifL)
      {
        this.css.width = this.maxL + "px";
        this.css.height = this.maxH +"px";
        this.windowCenter(this.contentImage);
        clearTimeout(this.timer);
      this.imgCurrent.style.visibility = "visible";
        this.appendImg();
        this.fadePic(0,100,this.imgCurrent);
      }
      else
      {
        this.windowCenter(this.contentImage);
        var temp = this;
        this.timer = setTimeout(function(){temp.openBox();},20);
      }
}
 
mBox.prototype.windowCenter = function(elementT) 
    {
      result=this.returnSize();
      var myWidth=result[0];
      var myHeight=result[1];
      var elementWidth=elementT.offsetWidth;
      var elementHeight=elementT.offsetHeight;
      var myScrollLeft=document.documentElement.scrollLeft;
      var myScrollTop=document.documentElement.scrollTop;
      var posX=myScrollLeft+myWidth-myWidth/2-elementWidth/2
      var posY=myScrollTop+myHeight-myHeight/2-elementHeight/2;
      elementT.style.left=posX+"px";
      elementT.style.top=posY+"px";
    } 
 
mBox.prototype.appendImg = function()
    {
      var temp = this;
      //Ajout de l'élément dans la div avec les tailles redimensionnée
      this.imgCurrent.style.width = this.maxL + "px";
      this.imgCurrent.style.height = this.maxH + "px";
      this.contentImage.appendChild(this.imgCurrent);
      this.windowCenter(this.imgCurrent);
      //Ajout du filtre
      if(this.IsIE)
      {
        this.imgCurrent.style.filter='alpha(opacity=0)';
        this.imgCurrent.filters[0].opacity=0;
      }
      else
      {
        this.imgCurrent.style.opacity='0';
      }
      //Nom de l'image
      //this.spanInfo.innerHTML = this.imgCurrent.src.substring(this.imgCurrent.src.lastIndexOf("\/")+1).split(".")[0]+"<br />";
    }
 
mBox.prototype.fadePic = function(debut, fin , element)
    {
      if(debut==fin){return false}
      this.IsIE?element.filters[0].opacity=debut:element.style.opacity=debut/100;
      debut>fin?debut-=5:debut+=5;
      var temp  = this ;
      if(debut != fin)
      {
        this.timer2 = setTimeout(function(){temp.fadePic(debut,fin,element);},10);
      }
      else
      {
        clearTimeout(this.timer2);
      }
    }
 
mBox.prototype.getAllImage = function(){
    //On récupère toutes les images de notre liste , puis on ajoute au tableau toute les images des balises alt
    var listeImg =  this.conteneur.getElementsByTagName('img');
    var temp = this ;
    var indexImg = 0 ;
    for(var i = 0 , l = listeImg.length ; i < l ; i++){
        //On ajoute l'image
        this.arrayImage.push(listeImg[i].alt);
        //On lui affecte une méthode sur le onclick pour l'afficher elle et une propriété indiquant son index
        listeImg[i].indexImg = i ;
        listeImg[i].onclick = function(){temp.seeCurent(this.indexImg);};
        //Si le preload est activé
        if(this.preload == true){
            var imgTemp =  document.createElement('img');
            imgTemp.src = listeImg[i].alt;
        }
    }
}
 
  mBox.prototype.newElement = function (parameter){
        var typeElement = parameter['typeElement'];
        var classToAffect = parameter['classeCss'];
        var parent = parameter['parent'];
 
        var newElement = document.createElement(typeElement);
        newElement.className = classToAffect;
        if(parent == null){
            document.body.appendChild(newElement);
        }
        else{
            parent.appendChild(newElement);
        }
        return newElement;
    }
 
    mBox.prototype.seeCurentPosition = function(){
        this.indicator.innerHTML =  (this.indexCurrent+1)+ " / " +this.arrayImage.length ;
        this.imageInformation .innerHTML = this.imgCurrent.src.substring(this.imgCurrent.src.lastIndexOf("\/")+1).split(".")[0]
    }
</script>
 
</head>
<body>
<div id="titi">
<img src="photos/pic1.jpg" alt="photos/pic1.jpg" width="100px">
        <img src="photos/pic2.jpg" alt="photos/pic2.jpg" width="100px">
        <img src="photos/pic3.jpg" alt="photos/pic3.jpg" width="100px">
        <img src="photos/pic4.jpg" alt="photos/pic4.jpg" width="100px">
        <img src="photos/pic5.jpg" alt="photos/pic5.jpg" width="100px">
        <img src="photos/pic6.jpg" alt="photos/pic6.jpg" width="100px">
        <img src="photos/pic7.jpg" alt="photos/pic7.jpg" width="100px">
        <img src="photos/pic8.jpg" alt="photos/pic8.jpg" width="100px">
        <img src="photos/pic9.jpg" alt="photos/pic9.jpg" width="100px">
        <img src="photos/pic10.jpg" alt="photos/pic10.jpg" width="100px">
        <img src="photos/plitvicka.jpg" alt="photos/plitvicka.jpg" width="100px">
        <img src="photos/pic12.jpg" alt="http://www.worldinhd.com/movabletype/archives/news/carsHD-thumb.jpg" width="100px">
</div>
<script type="text/javascript">
var test = new mBox(document.getElementById('titi'),true);
</script>
</body>
</html>
Amélioration / changelog :

- instanciation ultra simplifié exemple :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
var test = new mBox(document.getElementById('titi'),true);
titi étant le conteneur des images

- compatibilité accrue IE7/IE6/FF/CHROME/SAFARI
- Design plus sobre
- Position fixed ajouté si le contenu est beaucoup plus bas que la hauteur de page
- Totalement non intrusif

Encore une victoire de canard ^^

je laisse les démos en ligne de la v1 pour ceux que ça intéresse