IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Effet sur image


Sujet :

JavaScript

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 36
    Points : 18
    Points
    18
    Par défaut Effet sur image
    Bonjour,

    Je voudrais reproduire cet effet sur image
    http://www.difusiongrafica.com/inicio.html

    Comment faire?

    Merci par avance

  2. #2
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Points : 4 835
    Points
    4 835
    Par défaut
    salut , tu peux t'inspirer tu code dans les contributions :

    http://www.developpez.net/forums/d63...ements-4-sens/
    ça donne :

    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
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    	.slideIn{
    		overflow:hidden;
    		width:127px;
    		height:95px;
    		background-color:#FFFFFF;
    		border:1px solid #000000;
    		position:relative;
    	}
    	.slideIn img{
    		width:127px;
    		height:95px;
    		position:absolute;
    		display:none;
    	}
    </style>
    <script type="text/javascript">
     
    var SlideIn = function(){
    	//Variable globale
    	this.idObj = null;
    	this.timer = null;
    	this.from = null;
    	this.to = null;
    	this.direction = null;
    	//Tableau d'élément a déplacé
    	this.elementToSlide = new Array();
    	//Index de l'élément en cours
    	this.currentIndex = 0;
    	//Paramètre pour lancement automatique
    	this.timePause = 0 ; //permet de définir le temps de pause entre deux slide
    	this.auto = false ; //Permet d'activer ou non le slide automatique
    	}
     
    	/*##########################################################
    	####################  On ajoute les méthodes sur l'objet  ###################
    	##########################################################*/
    	//Permet de récupérer un élément par id
    	SlideIn.prototype.$ = function(element){
    		return document.getElementById(element);
    	};
     
    	//Méthode permettant de lancer les animations si en auto :)
    	SlideIn.prototype.go = function(){
    		if(this.auto){
    			switch (this.direction ){
    				case 'left':
    					this.SlideToLeft();
    				break;
    				case 'right':
    					this.SlideToRight();
    				break;
    				case 'top':
    					this.SlideToTop();
    				break;
    				case 'bottom':
    					this.SlideToBottom();
    				break;
    			}
    		}
    	}
     
    	//Méthode permettant d'ajouter un élément
    	SlideIn.prototype.AddElement = function(element){
    		if(typeof(element) == "string"){
    			this.elementToSlide.push(this.$(element));
    		}
    		else if(typeof(element) == "object"){
    			this.elementToSlide.push(element);
    		}
    	}
     
    	//Méthode permettant d'ajouter plusieurs élément d'un coup
    	SlideIn.prototype.AddElements = function (elements){
    		for(var i = 0 , l = elements.length; i < l ;i++){
    			this.AddElement(elements[i]);
    		}
    	}
     
    	//Méthode permettant de déplacer les éléments vers la gauche
    	SlideIn.prototype.SlideToLeft = function(){
    		if(this.direction == null || this.direction == 'left'){
    			var me = this ;
    			//On vérifit la direction pour initialiser le positionnement
    			if(this.direction != 'left'){
    					this.direction = 'left';
    					if(this.timer == null){
    						this.Positionne();
    					}
    			}
    			else if(this.direction == 'left' && this.auto && this.timer == null){
    				this.Positionne();
    			}
     
    			if(this.timer != null){
    				clearTimeout(this.timer);
    				this.timer = null;
    			}
    			//Si le timer n'est pas finit on détruit l'ancienne div
    			if(parseInt(this.from.style.left) == Number.NaN || (parseInt(this.from.parentNode.offsetWidth) + parseInt(this.from.style.left))> 0){
    				this.from.style.left = parseInt(this.from.style.left) - 15 + "px";
    				this.to.style.left  =parseInt(this.to.style.left) - 15 + "px";
    				//alert((parseInt(this.$(from).offsetWidth) + parseInt(this.$(from).style.left)));
    				this.timer = setTimeout(function(){me.SlideToLeft()},25);
    			}
    			else{
    				clearTimeout(this.timer);
    				this.timer = null;
    				this.currentIndex = (this.currentIndex == (this.elementToSlide.length-1)) ? 0:this.currentIndex + 1;
    				this.$('debug').innerHTML = this.currentIndex;
    				this.Positionne();
    				if(this.auto){
    					setTimeout(function(){me.SlideToLeft()},this.timePause);
    				}
    				else{
    					this.direction = null;
    				}
    			}
    		}
    	};
     
    	//Méthode permettant de déplacer les éléments vers la droite
    	SlideIn.prototype.SlideToRight = function(){
    		var me = this ;
    		if(this.direction == null || this.direction == 'right'){
    				if(this.direction != 'right'){
    					this.direction = 'right';
    					if(this.timer == null){
    						this.Positionne();
    					}
    				}
    				else if(this.direction == 'right' && this.auto && this.timer == null){
    					this.Positionne();
    				}
     
    				if(this.timer != null){
    					clearTimeout(this.timer);
    					this.timer = null;
    				}
    				//Si le timer n'est pas finit on détruit l'ancienne div
    				if(parseInt(this.from.style.left) == Number.NaN ||  parseInt(this.from.style.left) < parseInt(this.from.parentNode.offsetWidth)){
    					this.from.style.left = parseInt(this.from.style.left) + 15 + "px";
    					this.to.style.left  =parseInt(this.to.style.left) + 15 + "px";
    					//alert((parseInt(this.$(from).offsetWidth) + parseInt(this.$(from).style.left)));
    					this.timer = setTimeout(function(){me.SlideToRight()},25);
    				}
    				else{
    					clearTimeout(this.timer);
    					this.timer = null;
    					this.currentIndex = (this.currentIndex == 0) ? this.elementToSlide.length-1:this.currentIndex - 1;
    					this.Positionne();
    					if(this.auto){
    						setTimeout(function(){me.SlideToRight()},this.timePause);
    					}
    					else{
    						this.direction = null;
    					}
    				}
    		}
     
     
    	};
     
    	//Méthode permettant de déplacer les éléments vers la gauche
    	SlideIn.prototype.SlideToTop = function(){
    		var me = this ;
    		if(this.direction == null || this.direction == 'top'){
    			//On vérifit la direction pour initialiser le positionnement
    			if(this.direction != 'top'){
    					this.direction = 'top';
    					if(this.timer == null){
    						this.Positionne();
    					}
    			}
    			if(this.timer != null){
    				clearTimeout(this.timer);
    				this.timer = null;
    			}
    			//Si le timer n'est pas finit on détruit l'ancienne div
    			if(parseInt(this.from.style.top) == Number.NaN || (parseInt(this.from.style.top) > - parseInt(this.from.parentNode.offsetHeight))){
    				this.from.style.top = parseInt(this.from.style.top) - 15 + "px";
    				this.to.style.top  =parseInt(this.to.style.top) - 15 + "px";
    				this.timer = setTimeout(function(){me.SlideToTop()},25);
    			}
    			else{
    				clearTimeout(this.timer);
    				this.timer = null;
    				this.currentIndex = (this.currentIndex == 0) ? this.elementToSlide.length-1:this.currentIndex - 1;
    				this.Positionne();					
    				if(this.auto){
    					setTimeout(function(){me.SlideToTop()},this.timePause);
    				}
    				else{
    					this.direction = null;
    				}
    			}
    		}
    	};
     
    	//Méthode permettant de déplacer les éléments vers le bas
    	SlideIn.prototype.SlideToBottom = function(){
    		var me = this 
    		if(this.direction == null || this.direction == 'bottom'){
    			//On vérifit la direction pour initialiser le positionnement
    			if(this.direction != 'bottom'){
    					this.direction = 'bottom';
    					if(this.timer == null){
    						this.Positionne();
    					}
    			}
    			if(this.timer != null){
    				clearTimeout(this.timer);
    				this.timer = null;
    			}
    			//Si le timer n'est pas finit on détruit l'ancienne div
    			if(parseInt(this.from.style.top) == Number.NaN || parseInt(this.from.style.top) < parseInt(this.from.parentNode.offsetHeight)){
    				this.from.style.top = parseInt(this.from.style.top) + 15 + "px";
    				this.to.style.top  =parseInt(this.to.style.top) + 15 + "px";
    				this.timer = setTimeout(function(){me.SlideToBottom()},25);
    			}
    			else{
    				clearTimeout(this.timer);
    				this.timer = null;
    				this.currentIndex = (this.currentIndex == this.elementToSlide.length-1) ? 0:this.currentIndex + 1;
    				this.Positionne();
    				if(this.auto){
    					setTimeout(function(){me.SlideToBottom()},this.timePause);
    				}
    				else{
    					this.direction = null;
    				}
    			}
    		}
    	};
     
    	//Fonction initialisant le tableau en positionnant tous les éléments :)
    	SlideIn.prototype.Positionne = function(){
    		if(this.direction == 'left'){
    			//On vérifit que l'on est pas a la fin sinon le premier devient le dernier
    			if(this.currentIndex == this.elementToSlide.length-1){
    				//récupération des éléments : 
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[0]; //Premier élément
    			}
    			else{
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.currentIndex + 1];
    			}
    				this.from.style.display = "block" ;
    				this.from.style.left = 0 + "px";
    				this.to.style.left = this.from.parentNode.offsetWidth + "px";
    				this.to.style.display = "block";
    				//Posionement vertical
    				this.to.style.top = 0 + "px";
    				this.from.style.top = 0 + "px" ;
    		}
    		else if(this.direction == 'right'){
    			if(this.currentIndex == 0){
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.elementToSlide.length-1]; // dernier élément
    			}
    			else{
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.currentIndex-1];
    			}
    			this.from.style.display = "block" ;
    			this.from.style.left = 0 + "px";
    			this.to.style.left = - (this.from.parentNode.offsetWidth )+ "px";
    			this.to.style.display = "block";
    			//Posionement vertical
    			this.to.style.top = 0 + "px";
    			this.from.style.top = 0 + "px" ;
    		}
    		else if(this.direction == 'bottom'){
    			if(this.currentIndex == this.elementToSlide.length-1){
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[0]; // dernier élément
    			}
    			else{
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.currentIndex+1];
    			}
    			this.from.style.display = "block" ;
    			this.from.style.top = 0 + "px";
    			this.to.style.top = - (this.from.parentNode.offsetHeight )+ "px";
    			this.to.style.display = "block";
    			//Posionement horizontal
    			this.to.style.left = 0 + "px";
    			this.from.style.left = 0 + "px" ;
    		}
    		else if(this.direction == 'top'){
    			if(this.currentIndex == 0){
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.elementToSlide.length-1]; // dernier élément
    			}
    			else{
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.currentIndex-1];
    			}
    			this.from.style.display = "block" ;
    			this.from.style.top = 0 + "px";
    			this.to.style.top = (this.from.parentNode.offsetHeight )+ "px";
    			this.to.style.display = "block";
    			//Posionement horizontal
    			this.to.style.left = 0 + "px";
    			this.from.style.left = 0 + "px" ;
    		}
    	};
    </script>
    </head>
    <body>
     
    <div class="slideIn">
    	<img src="demo_galerie/galerie.php_fichiers/mini.jpg" style="display:block" width="127" height="95" id="la1" onMouseOver="newSlide.SlideToTop();"/>
        <img src="demo_galerie/galerie.php_fichiers/mini_002.jpg" id="la2" onmouseout="newSlide.SlideToBottom();"/>
    </div>
     
     
    <script type="text/javascript">
    //On instancie un slide
    var newSlide = new SlideIn();
    //On ajoute les éléments souhaités ( ici un tableau )  on peut utiliser la méthode AddElement pour ajouter un seul élément. on peut ajouter un id ou directement l'élément ;-)
    newSlide.AddElements(Array('la1','la2'));
     
    </script>
    </body>
    </html>

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    ca ne m'a pas pêrmis a trouver l'effet désiré

  4. #4
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    Faut pas non plus que l'on vienne te le servir sur un plateu d'argent ... ?

    La solution de Le_Chomeur est très proche, juste mettre un div à la place du la2

  5. #5
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Points : 4 835
    Points
    4 835
    Par défaut
    effectivement :

    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
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    	.slideIn{
    		overflow:hidden;
    		width:127px;
    		height:95px;
    		background-color:#FFFFFF;
    		border:1px solid #000000;
    		position:relative;
    		background-image:url('demo_galerie/galerie.php_fichiers/mini.jpg');
    	}
    	.slideIn img{
    		width:127px;
    		height:95px;
    		position:absolute;
    		display:none;
    	}
    </style>
    <script type="text/javascript">
     
    var SlideIn = function(){
    	//Variable globale
    	this.idObj = null;
    	this.timer = null;
    	this.from = null;
    	this.to = null;
    	this.direction = null;
    	//Tableau d'élément a déplacé
    	this.elementToSlide = new Array();
    	//Index de l'élément en cours
    	this.currentIndex = 0;
    	//Paramètre pour lancement automatique
    	this.timePause = 0 ; //permet de définir le temps de pause entre deux slide
    	this.auto = false ; //Permet d'activer ou non le slide automatique
    	}
     
    	/*##########################################################
    	####################  On ajoute les méthodes sur l'objet  ###################
    	##########################################################*/
    	//Permet de récupérer un élément par id
    	SlideIn.prototype.$ = function(element){
    		return document.getElementById(element);
    	};
     
    	//Méthode permettant de lancer les animations si en auto :)
    	SlideIn.prototype.go = function(){
    		if(this.auto){
    			switch (this.direction ){
    				case 'left':
    					this.SlideToLeft();
    				break;
    				case 'right':
    					this.SlideToRight();
    				break;
    				case 'top':
    					this.SlideToTop();
    				break;
    				case 'bottom':
    					this.SlideToBottom();
    				break;
    			}
    		}
    	}
     
    	//Méthode permettant d'ajouter un élément
    	SlideIn.prototype.AddElement = function(element){
    		if(typeof(element) == "string"){
    			this.elementToSlide.push(this.$(element));
    		}
    		else if(typeof(element) == "object"){
    			this.elementToSlide.push(element);
    		}
    	}
     
    	//Méthode permettant d'ajouter plusieurs élément d'un coup
    	SlideIn.prototype.AddElements = function (elements){
    		for(var i = 0 , l = elements.length; i < l ;i++){
    			this.AddElement(elements[i]);
    		}
    	}
     
    	//Méthode permettant de déplacer les éléments vers la gauche
    	SlideIn.prototype.SlideToLeft = function(){
    		if(this.direction == null || this.direction == 'left'){
    			var me = this ;
    			//On vérifit la direction pour initialiser le positionnement
    			if(this.direction != 'left'){
    					this.direction = 'left';
    					if(this.timer == null){
    						this.Positionne();
    					}
    			}
    			else if(this.direction == 'left' && this.auto && this.timer == null){
    				this.Positionne();
    			}
     
    			if(this.timer != null){
    				clearTimeout(this.timer);
    				this.timer = null;
    			}
    			//Si le timer n'est pas finit on détruit l'ancienne div
    			if(parseInt(this.from.style.left) == Number.NaN || (parseInt(this.from.parentNode.offsetWidth) + parseInt(this.from.style.left))> 0){
    				this.from.style.left = parseInt(this.from.style.left) - 15 + "px";
    				this.to.style.left  =parseInt(this.to.style.left) - 15 + "px";
    				//alert((parseInt(this.$(from).offsetWidth) + parseInt(this.$(from).style.left)));
    				this.timer = setTimeout(function(){me.SlideToLeft()},25);
    			}
    			else{
    				clearTimeout(this.timer);
    				this.timer = null;
    				this.currentIndex = (this.currentIndex == (this.elementToSlide.length-1)) ? 0:this.currentIndex + 1;
    				this.$('debug').innerHTML = this.currentIndex;
    				this.Positionne();
    				if(this.auto){
    					setTimeout(function(){me.SlideToLeft()},this.timePause);
    				}
    				else{
    					this.direction = null;
    				}
    			}
    		}
    	};
     
    	//Méthode permettant de déplacer les éléments vers la droite
    	SlideIn.prototype.SlideToRight = function(){
    		var me = this ;
    		if(this.direction == null || this.direction == 'right'){
    				if(this.direction != 'right'){
    					this.direction = 'right';
    					if(this.timer == null){
    						this.Positionne();
    					}
    				}
    				else if(this.direction == 'right' && this.auto && this.timer == null){
    					this.Positionne();
    				}
     
    				if(this.timer != null){
    					clearTimeout(this.timer);
    					this.timer = null;
    				}
    				//Si le timer n'est pas finit on détruit l'ancienne div
    				if(parseInt(this.from.style.left) == Number.NaN ||  parseInt(this.from.style.left) < parseInt(this.from.parentNode.offsetWidth)){
    					this.from.style.left = parseInt(this.from.style.left) + 15 + "px";
    					this.to.style.left  =parseInt(this.to.style.left) + 15 + "px";
    					//alert((parseInt(this.$(from).offsetWidth) + parseInt(this.$(from).style.left)));
    					this.timer = setTimeout(function(){me.SlideToRight()},25);
    				}
    				else{
    					clearTimeout(this.timer);
    					this.timer = null;
    					this.currentIndex = (this.currentIndex == 0) ? this.elementToSlide.length-1:this.currentIndex - 1;
    					this.Positionne();
    					if(this.auto){
    						setTimeout(function(){me.SlideToRight()},this.timePause);
    					}
    					else{
    						this.direction = null;
    					}
    				}
    		}
     
     
    	};
     
    	//Méthode permettant de déplacer les éléments vers la gauche
    	SlideIn.prototype.SlideToTop = function(){
    		var me = this ;
    		if(this.direction == null || this.direction == 'top'){
    			//On vérifit la direction pour initialiser le positionnement
    			if(this.direction != 'top'){
    					this.direction = 'top';
    					if(this.timer == null){
    						this.Positionne();
    					}
    			}
    			if(this.timer != null){
    				clearTimeout(this.timer);
    				this.timer = null;
    			}
    			//Si le timer n'est pas finit on détruit l'ancienne div
    			if(parseInt(this.from.style.top) == Number.NaN || (parseInt(this.from.style.top) > - parseInt(this.from.parentNode.offsetHeight))){
    				this.from.style.top = parseInt(this.from.style.top) - 15 + "px";
    				this.to.style.top  =parseInt(this.to.style.top) - 15 + "px";
    				this.timer = setTimeout(function(){me.SlideToTop()},25);
    			}
    			else{
    				clearTimeout(this.timer);
    				this.timer = null;
    				this.currentIndex = (this.currentIndex == 0) ? this.elementToSlide.length-1:this.currentIndex - 1;
    				this.Positionne();					
    				if(this.auto){
    					setTimeout(function(){me.SlideToTop()},this.timePause);
    				}
    				else{
    					this.direction = null;
    				}
    			}
    		}
    	};
     
    	//Méthode permettant de déplacer les éléments vers le bas
    	SlideIn.prototype.SlideToBottom = function(){
    		var me = this 
    		if(this.direction == null || this.direction == 'bottom'){
    			//On vérifit la direction pour initialiser le positionnement
    			if(this.direction != 'bottom'){
    					this.direction = 'bottom';
    					if(this.timer == null){
    						this.Positionne();
    					}
    			}
    			if(this.timer != null){
    				clearTimeout(this.timer);
    				this.timer = null;
    			}
    			//Si le timer n'est pas finit on détruit l'ancienne div
    			if(parseInt(this.from.style.top) == Number.NaN || parseInt(this.from.style.top) < parseInt(this.from.parentNode.offsetHeight)){
    				this.from.style.top = parseInt(this.from.style.top) + 15 + "px";
    				this.to.style.top  =parseInt(this.to.style.top) + 15 + "px";
    				this.timer = setTimeout(function(){me.SlideToBottom()},25);
    			}
    			else{
    				clearTimeout(this.timer);
    				this.timer = null;
    				this.currentIndex = (this.currentIndex == this.elementToSlide.length-1) ? 0:this.currentIndex + 1;
    				this.Positionne();
    				if(this.auto){
    					setTimeout(function(){me.SlideToBottom()},this.timePause);
    				}
    				else{
    					this.direction = null;
    				}
    			}
    		}
    	};
     
    	//Fonction initialisant le tableau en positionnant tous les éléments :)
    	SlideIn.prototype.Positionne = function(){
    		if(this.direction == 'left'){
    			//On vérifit que l'on est pas a la fin sinon le premier devient le dernier
    			if(this.currentIndex == this.elementToSlide.length-1){
    				//récupération des éléments : 
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[0]; //Premier élément
    			}
    			else{
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.currentIndex + 1];
    			}
    				this.from.style.display = "block" ;
    				this.from.style.left = 0 + "px";
    				this.to.style.left = this.from.parentNode.offsetWidth + "px";
    				this.to.style.display = "block";
    				//Posionement vertical
    				this.to.style.top = 0 + "px";
    				this.from.style.top = 0 + "px" ;
    		}
    		else if(this.direction == 'right'){
    			if(this.currentIndex == 0){
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.elementToSlide.length-1]; // dernier élément
    			}
    			else{
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.currentIndex-1];
    			}
    			this.from.style.display = "block" ;
    			this.from.style.left = 0 + "px";
    			this.to.style.left = - (this.from.parentNode.offsetWidth )+ "px";
    			this.to.style.display = "block";
    			//Posionement vertical
    			this.to.style.top = 0 + "px";
    			this.from.style.top = 0 + "px" ;
    		}
    		else if(this.direction == 'bottom'){
    			if(this.currentIndex == this.elementToSlide.length-1){
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[0]; // dernier élément
    			}
    			else{
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.currentIndex+1];
    			}
    			this.from.style.display = "block" ;
    			this.from.style.top = 0 + "px";
    			this.to.style.top = - (this.from.parentNode.offsetHeight )+ "px";
    			this.to.style.display = "block";
    			//Posionement horizontal
    			this.to.style.left = 0 + "px";
    			this.from.style.left = 0 + "px" ;
    		}
    		else if(this.direction == 'top'){
    			if(this.currentIndex == 0){
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.elementToSlide.length-1]; // dernier élément
    			}
    			else{
    				this.from = this.elementToSlide[this.currentIndex];
    				this.to = this.elementToSlide[this.currentIndex-1];
    			}
    			this.from.style.display = "block" ;
    			this.from.style.top = 0 + "px";
    			this.to.style.top = (this.from.parentNode.offsetHeight )+ "px";
    			this.to.style.display = "block";
    			//Posionement horizontal
    			this.to.style.left = 0 + "px";
    			this.from.style.left = 0 + "px" ;
    		}
    	};
    </script>
    </head>
    <body>
     
    <div class="slideIn">
    	<div id="la1" style="width:127px;height:95px;" onMouseOver="newSlide.SlideToTop();"></div>
        <img src="demo_galerie/galerie.php_fichiers/mini_002.jpg" id="la2" onMouseOut="newSlide.SlideToBottom();"/>
    </div>
     
     
    <script type="text/javascript">
    //On instancie un slide
    var newSlide = new SlideIn();
    //On ajoute les éléments souhaités ( ici un tableau )  on peut utiliser la méthode AddElement pour ajouter un seul élément. on peut ajouter un id ou directement l'élément ;-)
    newSlide.AddElements(Array('la1','la2'));
     
    </script>
    </body>
    </html>
    donne exactement le resultat escompté ...

  6. #6
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 681
    Points : 5 221
    Points
    5 221
    Par défaut
    autre code basique:

    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
    <title> ... </title> 
     
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
     
    <style type="text/css">
     
    .cont {
    	float:left;
    	overflow:hidden;
    	position:relative;
    	padding:0px;
    	width:200px;
    	height:200px;
    	margin:50px
    }
     
    .cont div {
    	background:gray;
    	position:relative;
    	width:200px;
    	height:200px;
    	margin:0px;
    	padding:10px
    }
     
    .cont img {
    	width:200px;
    	height:200px
    } 
     
    </style>
     
    </head> 
    <body> 
     
    <div id="galerie">
     
    <div id="conteneur0" class="cont">
     	<img src="cox.gif" />
    	<div id="cache0">
    		<a href="#" title="lien bidon">Bonjour tout le monde</a>
    		<br />Rien d'autre à dire pour le moment.
    	</div>
    </div>
     
    <div id="conteneur1" class="cont">
     	<img src="cox.gif" />
    	<div id="cache1">
    		<a href="#" title="lien bidon">Bonjour tout le monde</a>
    		<br />Rien d'autre à dire pour le moment.
    	</div>
    </div>
     
    <div id="conteneur2" class="cont">
     	<img src="cox.gif" />
    	<div id="cache2">
    		<a href="#" title="lien bidon">Bonjour tout le monde</a>
    		<br />Rien d'autre à dire pour le moment.
    	</div>
    </div>
     
    <div id="conteneur3" class="cont">
     	<img src="cox.gif" />
    	<div id="cache3">
    		<a href="#" title="lien bidon">Bonjour tout le monde</a>
    		<br />Rien d'autre à dire pour le moment.
    	</div>
    </div>
     
    <div id="conteneur4" class="cont">
     	<img src="cox.gif" />
    	<div id="cache4">
    		<a href="#" title="lien bidon">Bonjour tout le monde</a>
    		<br />Rien d'autre à dire pour le moment.
    	</div>
    </div>
     
    <div id="conteneur5" class="cont">
     	<img src="cox.gif" />
    	<div id="cache5">
    		<a href="#" title="lien bidon">Bonjour tout le monde</a>
    		<br />Rien d'autre à dire pour le moment.
    	</div>
    </div>
     
    </div>
     
    <script type="text/javascript"> 
     
    var tab=[]
     
    for(i=0;i!=document.getElementById("galerie").getElementsByTagName("img").length;i++){
    	tab[i]=new go(document.getElementById("cache"+i))
     
    	document.getElementById("conteneur"+i).ind=i;
     
    	document.getElementById("conteneur"+i).onmouseover=function(e){
    		tab[this.ind].sens=true;
    		clearInterval(tab[this.ind].timer);
    		tab[this.ind].timer=setInterval("tab["+this.ind+"].b()",1)
    	}
     
    	document.getElementById("conteneur"+i).onmouseout=function(e){
    		tab[this.ind].sens=false;
    		clearInterval(tab[this.ind].timer);
    		tab[this.ind].timer=setInterval("tab["+this.ind+"].b()",1)
    	}
    }
     
     
    function go(val){
    	this.v=val;
    	this.timer;
    	this.pos=0;
    	this.sens;
     
    }
    function bouge(){
    		if(this.sens){		
    			if(this.pos>=-200){
    				this.pos-=10
    			}
    		}
    		else{
    			if(this.pos<0){
    				this.pos+=20
    			}
    		}
    		this.v.style.top=this.pos+'px';		
    }
     
    go.prototype.b=bouge;
     
     
    </script> 
     
    </body>
    </html>
    démo: http://javatwist.imingo.net/test.htm

Discussions similaires

  1. Recherche effet sur image
    Par luffyfr dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 02/03/2011, 14h53
  2. effet autocollant sur image
    Par sssensiiia dans le forum Flash
    Réponses: 2
    Dernier message: 08/06/2007, 16h24
  3. effet sur image dans td background
    Par prodi_64 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 21/08/2006, 12h10
  4. effet sur image sous Firefox
    Par la.sophe dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 18/04/2006, 15h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo