Bonjour,
Le script composé de deux fichers permet de faire defiler du texte de haut en bas sur un cadre.
Je suis bloqué à quelque chose depuis assez longtemps.
Je suis sûr qu'il y a une solution toute bête à ce problème ou alors cela vient de moi, j'essaye de mettre dans un tableau javascript des valeurs venant de php ... je passe par le echo pour implenter du code js sur la page.
Le problème étant, quand je mets de simples valeurs dans le tableau js du genre :
<?php echo "elements[$i]='salut';" ; ?>
avec elements tableau js.
Cela fonctionne mais quand je continue avec quelque chose de plus complexe le texte ne s'affichage pas.
Je vous partage ci-dessous le contenu des deux fichiers, car un exemple vos mieux que 10000 mots.
Voici le code qui s'affichera sur la page html
Voici le script js :
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 <head> <script language="JavaScript" src="textdefil1.js"></script> <STYLE TYPE="text/css"> .txt_defil {font-size:11px;font-family:Verdana;color:#FFFFFF;;text-decoration:none;margin-left:20px;} .txt_defil:link {font-size:11px;font-family:Verdana;color:#FFFFFF;;text-decoration:none} .txt_defil:visited {font-size:11px;font-family:Verdana;color:#FFFFFF;;text-decoration:none} .txt_defil:hover {font-size:11px;font-family:Verdana;color:#FFCCFF;;text-decoration:underline} body{ font-size:10px; } </STYLE> </head> <body> <div id="nuage" style="top:1;">HAAAAAAAA</div> <div style="margin-left:300px;float:left;"><img src ="2010_10_30_1800_MSG2_9_S1_grid.jpeg" width="400" height="400"/><br/><br/> <?php echo " <script language=\"JavaScript\"> var txt_defil_width = 150; //largeur var txt_defil_height = 400; //hauteur var txt_defil_bgcolor = '#000000'; //couleur de fond var txt_defil_background = '#FF1100'; //image de fond var txt_defil_info = new Array; var elements = new Array; "; $fichier='links'; $fp=fopen($fichier, 'r'); $i=0; $a = array(); while($c=fgets($fp, 1024)) { if(!ctype_space($c) && strlen($c) != 0) { $c = str_replace(' ', '', $c); $c = trim(preg_replace('#(.*)\r(.*)#', '$1,$2', $c)); $c = trim(preg_replace('#(.*)\s(.*)#', '$1,$2', $c)); $a[$i] = $c ; $i++; } } $n = count($a); for($z=0;$z<$n;$z++) { echo 'element['.$z.']=\''.$a[$z].'\';'; } echo " txt_defil_info[0]=''; for (var i = 0; i < elements.length; i++) { txt_defil_info[0] += elements[i]+'</br>'; } //--> </script>"; ?> <script language="JavaScript" src="textdefil1.js"></script> </body>
Merci
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 function writext(texdef) { document.write(texdef); } writext('<DIV ID=txt_defil_relativ onMouseOver="txt_defil_stop()" onMouseOut="txt_defil_rstart()" STYLE="position:relative;width:'+txt_defil_width +';height:'+txt_defil_height+';background-color:'+txt_defil_bgcolor+';background-image:url('+txt_defil_background+')">'); writext('<DIV ID=txt_defil_cadre STYLE="position:absolute;width:'+(txt_defil_width -8)+';height:'+(txt_defil_height-8)+';top:4;left:4;clip:rect(0 '+(txt_defil_width -8)+' '+(txt_defil_height-8)+' 0)">'); writext('<div id=txt_defiler_1 style="position:absolute;width:'+(txt_defil_width -8)+';left:0;top:0;" CLASS=txt_defil >'+txt_defil_info[0]+'</DIV>'); writext('<div id=txt_defiler_2 style="position:absolute;width:'+(txt_defil_width -8)+';left:0;top:'+txt_defil_height+';" CLASS=txt_defil >'+txt_defil_info[1]+'</DIV>'); writext('</DIV></DIV>'); txt_defil_1 =1; txt_defil_2 = 0; stop_mouss=0; function txt_defil_f1() { if(txt_defil_1 == 1) { txt_defil_haut = "txt_defiler_1"; txt_defil_bas = "txt_defiler_2"; txt_defil_1 = 0; } else { txt_defil_bas = "txt_defiler_1"; txt_defil_haut = "txt_defiler_2"; txt_defil_1 = 1; } txt_defil_nb_info = txt_defil_info.length-1; if(txt_defil_2 == txt_defil_nb_info) txt_defil_next = 0; else txt_defil_next = txt_defil_2+1; if(document.getElementById) document.getElementById(txt_defil_bas).innerHTML = txt_defil_info[txt_defil_next]; txt_defil_top = 0; if(document.getElementById) txt_defil_f2 () } function txt_defil_f2 () { if (stop_mouss == 0) { txt_defil_top += 1; document.getElementById(txt_defil_haut).style.top = txt_defil_top; document.getElementById(txt_defil_bas).style.top = txt_defil_top - txt_defil_height; if((txt_defil_top + txt_defil_height) < (txt_defil_height*2)) move2=setTimeout("txt_defil_f2 ()",20) else txt_defil_f3() } else move1=setTimeout("txt_defil_f2 ()",500) } function txt_defil_f3() { txt_defil_2 = txt_defil_next; txt_defil_f1() } function txt_defil_stop() { stop_mouss=1; } function txt_defil_rstart() { stop_mouss=0; } window.onload = txt_defil_f1;
Partager