Urmatorul script coloreaza textul dintr-un sir la fel cum puteti observa in exemplul de mai jos.
Pentru a adauga acest script intr-o pagina web:
1. In documentul HTML adaugati urmatorul script (preferabil in sectiunea HEAD)
<script type="text/javascript">
<!--
function MakeArray(n) {
this.length=n;
for(var i=1; i<=n; i++)
this[i]=i-1;
return this
}
hex=new MakeArray(16);
hex[11]="A";
hex[12]="B";
hex[13]="C";
hex[14]="D";
hex[15]="E";
hex[16]="F";
function InHex(x) {
// Schimba numarul in hex, cu valoarea intre 0 si 255
var high=x/16;
var s=high+"";
//1
s=s.substring(0,2);
//2 transforma valoarea in int.
high=parseInt(s,10);
//3
var left=hex[high+1];
// partea stanga a valorii hex
var low=x-high*16;
// calculeaza restul valorilor
s=low+"";
//1
s=s.substring(0,2);
//2 transforma valoarea in int.
low=parseInt(s,10);
//3
var right=hex[low+1];
// partea dreapta a valorii hex
var string=left+""+right;
// uneste partea stanga si cea din dreapta
return string;
}
function fadein(text) {
text=text.substring(3,text.length-4);
// a eliminat tag-urile html
color_d1=255;
color_d1b=255;
color_d1c=255;
// valorile numerice maxime pt. culori
mul=color_d1/text.length;
for(i=0;i<text.length;i++) {
color_d1=mul*i;
color_d1b=255-mul*i;
color_d1c=255*Math.sin(i/(text.length/3));
// colorarea sirului
color_h1=InHex(color_d1);
color_d2=255-mul*i;
color_h2=InHex(color_d2);
//1b
color_h1b=InHex(color_d1b);
color_d2b=mul*i;
color_h2b=InHex(color_d2b);
//1c
color_h1c=InHex(color_d1c);
color_d2c=mul*i;
color_h2c=InHex(color_d2c);
document.write("<span style='font-size:20px; color:#FE"+color_h1+color_h2+";'>"+text.substring(i,i+1)+'</span>');
}
}
//-->
</script>
<script type="text/javascript">
<!--
// Aici adaugati textul
{
fadein("-->Acesta este un exemplu de sir cu text colorat.<!__");
}
//-->
</script>
<div>Web Programming and Development</div>
h2 { text-decoration: underline; }
function someFunction() { alert("CoursesWeb.net"); } setTimeout("someFunction()", 2000);
$food =["fruits" =>["banana", "mar"), "veggie" =>["ceapa", "rosie")); $nr_food = count($food, 1); echo $nr_food; // 6
The child will haven't played by Sunday. - Copilul nu s-ar fi jucat pana duminica.
Él no habrá contado el cuento. - El nu ar fi spus povestea.