Bonjour,

j'ai récupéré sur internet un script de slider que j'ai couplé à un script de défilement d'image que j'avais codé, mais le script du slider affiche la valeur de celui-ci , et bien que sa veleur initiale soit 30, quand je redémarre le script, il affiche la dernière valeur qu'il avait prise lors de l'exécution précédente, au lieu de 30. Et je n'ai pas trouvé où c'était géré. Peut-on me le dire ? Voici le code js (j'ai mis des commentaires pour repérer les 2 sections de code) :
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
// Code du défilement d'image
 
var TEMPO_TIME = 5000;
var ViewNode;
var ImageNode;
var ImageWidth;
var ViewLeft;
var posx;
var sensposx;
var sens;
var clockId = null;
var depart;
var valueslide;
var step;
var defilspeed;
 
function init() {
 
	ViewNode=document.getElementById("view");  // récupération du div
	ImageNode=document.getElementById("image"); // récupération de l'image
	ImageWidth=ImageNode.width;		/* lecture de la largeur de l'image (car. HTML car la
	CSS est mal affichée) */
	ViewLeft=ViewNode.offsetLeft; // lecture de l'offset gauche du div (html)
	ViewRight=ViewLeft+ViewNode.offsetWidth; // calcul de l'offset droit du div (html)
	posx= ViewNode.offsetWidth;
	//alert('offsetWidth='+posx);
	sensposx=ViewRight;
	sens=1;
	depart=0;
	ViewNode.onmouseover = stopScrolling;
	ViewNode.onmouseout = startScrolling;
	step=1;
	defilspeed=30;
	//setInterval("move()", 30); // appel fct move ttes les 30 ms
 
	startScrolling();
}	
 
function startScrolling()  {
	if ( clockId == null ) {
		clockId = setInterval("move()", defilspeed);
	}
}
 
function stopScrolling()  {
	if ( clockId != null ) {
		clearInterval( clockId );
		clockId = null;
	}
}
 
function move() {
document.title=valueslide;
 
	if (valueslide<=10) {step=1; defilspeed=50; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else if (valueslide<=20) {step=1; defilspeed=40; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else if (valueslide<=30) {step=1; defilspeed=30; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else if (valueslide<=40) {step=1; defilspeed=20; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else if (valueslide<=50) {step=2; defilspeed=50; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else if (valueslide<=60) {step=2; defilspeed=40; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else if (valueslide<=70) {step=2; defilspeed=30; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else if (valueslide<=80) {step=2; defilspeed=20; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else if (valueslide<=90) {step=3; defilspeed=30; clearInterval( clockId ); clockId = setInterval("move()", defilspeed);}
	else {step=3; defilspeed=20; clearInterval( clockId );clockId = setInterval("move()", defilspeed);} 
 
	var tempoIsRequested = false;
	//document.title = 'VR='+ViewRight+'ssposx='+(sensposx)+'-sens='+sens;
	image.style.left=sensposx+"px"; /* écriture position de l'image ; bord gauche 
	(CSS pour écrire)*/ 
	posx=posx-step; 
	sensposx=depart+sens*posx+ViewLeft;
/* chgt de sens à gauche si bord droit de l'image atteint bord droit du conteneur */
/* ds les 2 cas, posx est initialisé à la largeur du conteneur et initialisation du décalage (depart) à la position */
/* initiale - l'offset du conteneur (sensposx-ViewLeft) et +/- la largeur du conteneur (pas compris) */	
	if ((sensposx+ImageWidth<=ViewRight)&&(sens==1)) {sens=-1; posx= ViewNode.offsetWidth; depart=sensposx-ViewLeft+ViewNode.offsetWidth; sensposx=depart+sens*posx+ViewLeft;}
	/* chgt de sens à droite si bord gauche de l'image atteint bord gauche du conteneur */
	else if ((sensposx>=ViewLeft-10)&&(sens==-1)){sens=1; posx= ViewNode.offsetWidth; depart=sensposx-ViewLeft-ViewNode.offsetWidth; sensposx=depart+sens*posx+ViewLeft;}
 
 
 
	} 
 
// début du code du slider
//
// Title: tigra slider control
// Description: See the demo at url
// URL: http://www.softcomplex.com/products/tigra_slider_control/
// Version: 1.0.2 (commented source)
// Date: 08/21/2008
// Tech. Support: http://www.softcomplex.com/forum/
// Notes: This script is free. Visit official site for further details.
 
 
function slider (a_init, a_tpl) {
 
	this.f_setValue  = f_sliderSetValue;
	this.f_getPos    = f_sliderGetPos;
 
	// register in the global collection	
	if (!window.A_SLIDERS)
		window.A_SLIDERS = [];
	this.n_id = window.A_SLIDERS.length;
	window.A_SLIDERS[this.n_id] = this;
 
	// save config parameters in the slider object
	var s_key;
	if (a_tpl)
		for (s_key in a_tpl)
			this[s_key] = a_tpl[s_key];
	for (s_key in a_init)
		this[s_key] = a_init[s_key];
 
	this.n_pix2value = this.n_pathLength / (this.n_maxValue - this.n_minValue);
	if (this.n_value == null)
		this.n_value = this.n_minValue;
 
	// generate the control's HTML
	document.write(
		'<div style="width:' + this.n_controlWidth + 'px;height:' + this.n_controlHeight + 'px;border:0; background-image:url(' + this.s_imgControl + ')" id="sl' + this.n_id + 'base">' +
		'<img src="' + this.s_imgSlider + '" width="' + this.n_sliderWidth + '" height="' + this.n_sliderHeight + '" border="0" style="position:relative;left:' + this.n_pathLeft + 'px;top:' + this.n_pathTop + 'px;z-index:' + this.n_zIndex + ';cursor:pointer;visibility:hidden;" name="sl' + this.n_id + 'slider" id="sl' + this.n_id + 'slider" onmousedown="return f_sliderMouseDown(' + this.n_id + ')"/></div>'
	);
	this.e_base   = get_element('sl' + this.n_id + 'base');
	this.e_slider = get_element('sl' + this.n_id + 'slider');
 
	// safely hook document/window events
	if (!window.f_savedMouseMove && document.onmousemove != f_sliderMouseMove) {
		window.f_savedMouseMove = document.onmousemove;
		document.onmousemove = f_sliderMouseMove;
	}
	if (!window.f_savedMouseUp && document.onmouseup != f_sliderMouseUp) {
		window.f_savedMouseUp = document.onmouseup;
		document.onmouseup = f_sliderMouseUp;
	}
	// preset to the value in the input box if available
	var e_input = this.s_form == null
		? get_element(this.s_name)
		: document.forms[this.s_form]
			? document.forms[this.s_form].elements[this.s_name]
			: null;
	this.f_setValue(e_input && e_input.value != '' ? e_input.value : null, 1);
 
	this.e_slider.style.visibility = 'visible';
}
 
function f_sliderSetValue (n_value, b_noInputCheck) {
	if (n_value == null)
		n_value = this.n_value == null ? this.n_minValue : this.n_value;
	if (isNaN(n_value))
		return false;
	// round to closest multiple if step is specified
	if (this.n_step)
		n_value = Math.round((n_value - this.n_minValue) / this.n_step) * this.n_step + this.n_minValue;
	// smooth out the result
	if (n_value % 1)
		n_value = Math.round(n_value * 1e5) / 1e5;
 
	if (n_value < this.n_minValue)
		n_value = this.n_minValue;
	if (n_value > this.n_maxValue)
		n_value = this.n_maxValue;
 
	this.n_value = n_value;
	valueslide=n_value;
 
 
	// move the slider
	if (this.b_vertical)
		this.e_slider.style.top  = (this.n_pathTop + this.n_pathLength - Math.round((n_value - this.n_minValue) * this.n_pix2value)) + 'px';
	else
		this.e_slider.style.left = (this.n_pathLeft + Math.round((n_value - this.n_minValue) * this.n_pix2value)) + 'px';
 
	// save new value
	var e_input;
	if (this.s_form == null) {
		e_input = get_element(this.s_name);
		if (!e_input)
			return b_noInputCheck ? null : f_sliderError(this.n_id, "Can not find the input with ID='" + this.s_name + "'.");
	}
	else {
		var e_form = document.forms[this.s_form];
		if (!e_form)
			return b_noInputCheck ? null : f_sliderError(this.n_id, "Can not find the form with NAME='" + this.s_form + "'.");
		e_input = e_form.elements[this.s_name];
		if (!e_input)
			return b_noInputCheck ? null : f_sliderError(this.n_id, "Can not find the input with NAME='" + this.s_name + "'.");
	}
	e_input.value = n_value;
}
 
// get absolute position of the element in the document
function f_sliderGetPos (b_vertical, b_base) {
	var n_pos = 0,
		s_coord = (b_vertical ? 'Top' : 'Left');
	var o_elem = o_elem2 = b_base ? this.e_base : this.e_slider;
 
	while (o_elem) {
		n_pos += o_elem["offset" + s_coord];
		o_elem = o_elem.offsetParent;
	}
	o_elem = o_elem2;
 
	var n_offset;
	while (o_elem.tagName != "BODY") {
		n_offset = o_elem["scroll" + s_coord];
		if (n_offset)
			n_pos -= o_elem["scroll" + s_coord];
		o_elem = o_elem.parentNode;
	}
	return n_pos;
}
 
function f_sliderMouseDown (n_id) {
	window.n_activeSliderId = n_id;
	return false;
}
 
function f_sliderMouseUp (e_event, b_watching) {
	if (window.n_activeSliderId != null) {
		var o_slider = window.A_SLIDERS[window.n_activeSliderId];
		o_slider.f_setValue(o_slider.n_minValue + (o_slider.b_vertical
			? (o_slider.n_pathLength - parseInt(o_slider.e_slider.style.top) + o_slider.n_pathTop)
			: (parseInt(o_slider.e_slider.style.left) - o_slider.n_pathLeft)) / o_slider.n_pix2value);
		if (b_watching)	return;
		window.n_activeSliderId = null;
	}
	if (window.f_savedMouseUp)
		return window.f_savedMouseUp(e_event);
}
 
function f_sliderMouseMove (e_event) {
 
	if (!e_event && window.event) e_event = window.event;
 
	// save mouse coordinates
	if (e_event) {
		window.n_mouseX = e_event.clientX + f_scrollLeft();
		window.n_mouseY = e_event.clientY + f_scrollTop();
	}
 
	// check if in drag mode
	if (window.n_activeSliderId != null) {
		var o_slider = window.A_SLIDERS[window.n_activeSliderId];
 
		var n_pxOffset;
		if (o_slider.b_vertical) {
			var n_sliderTop = window.n_mouseY - o_slider.n_sliderHeight / 2 - o_slider.f_getPos(1, 1) - 3;
			// limit the slider movement
			if (n_sliderTop < o_slider.n_pathTop)
				n_sliderTop = o_slider.n_pathTop;
			var n_pxMax = o_slider.n_pathTop + o_slider.n_pathLength;
			if (n_sliderTop > n_pxMax)
				n_sliderTop = n_pxMax;
			o_slider.e_slider.style.top = n_sliderTop + 'px';
			n_pxOffset = o_slider.n_pathLength - n_sliderTop + o_slider.n_pathTop;
		}
		else {
			var n_sliderLeft = window.n_mouseX - o_slider.n_sliderWidth / 2 - o_slider.f_getPos(0, 1) - 3;
			// limit the slider movement
			if (n_sliderLeft < o_slider.n_pathLeft)
				n_sliderLeft = o_slider.n_pathLeft;
			var n_pxMax = o_slider.n_pathLeft + o_slider.n_pathLength;
			if (n_sliderLeft > n_pxMax)
				n_sliderLeft = n_pxMax;
			o_slider.e_slider.style.left = n_sliderLeft + 'px';
			n_pxOffset = n_sliderLeft - o_slider.n_pathLeft;
		}
		if (o_slider.b_watch)
			 f_sliderMouseUp(e_event, 1);
 
		return false;
	}
 
	if (window.f_savedMouseMove)
		return window.f_savedMouseMove(e_event);
}
 
// get the scroller positions of the page
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
 
function f_sliderError (n_id, s_message) {
	alert("Slider #" + n_id + " Error:\n" + s_message);
	window.n_activeSliderId = null;
}
 
get_element = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };