03
Mar
2010
Mar
2010
Cara membuat text/tulisan pelangi
Posted by: adminCara membuat text/tulisan pelangi.
Ingin memperindah tampilan blog dengan tulisan pelangi seperti contoh dibawah??
Demo:
Langkah-langkahnya:
1. Pasang kode javascript berikut pada bagian <head> website/blog kamu
Salin kode JAVASCRIPT
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 | <script type="text/javascript"> <!-- Begin /* * Notes on hue * * This script uses hue rotation in the following manner: * hue=0 is red (#FF0000) * hue=60 is yellow (#FFFF00) * hue=120 is green (#00FF00) * hue=180 is cyan (#00FFFF) * hue=240 is blue (#0000FF) * hue=300 is magenta (#FF00FF) * hue=360 is hue=0 (#FF0000) * * Notes on the script * * This script should function in any browser that supports document.getElementById * It has been tested in Netscape7, Mozilla Firefox 1.0, and Internet Explorer 6 * * Accessibility * * The script does not write the string out, but rather takes it from an existing * HTML element. Therefore, users with javascript disabled will not be adverely affected. * They just won't get the pretty colors. */ /* * splits par.firstChild.data into 1 span for each letter * ARGUMENTS * span - HTML element containing a text node as the only element */ function toSpans(span) { var str=span.firstChild.data; var a=str.length; span.removeChild(span.firstChild); for(var i=0; i<a; i++) { var theSpan=document.createElement("SPAN"); theSpan.appendChild(document.createTextNode(str.charAt(i))); span.appendChild(theSpan); } } function RainbowSpan(span, hue, deg, brt, spd, hspd) { this.deg=(deg==null?360:Math.abs(deg)); this.hue=(hue==null?0:Math.abs(hue)%360); this.hspd=(hspd==null?3:Math.abs(hspd)%360); this.length=span.firstChild.data.length; this.span=span; this.speed=(spd==null?50:Math.abs(spd)); this.hInc=this.deg/this.length; this.brt=(brt==null?255:Math.abs(brt)%256); this.timer=null; toSpans(span); this.moveRainbow(); } RainbowSpan.prototype.moveRainbow = function() { if(this.hue>359) this.hue-=360; var color; var b=this.brt; var a=this.length; var h=this.hue; for(var i=0; i<a; i++) { if(h>359) h-=360; if(h<60) { color=Math.floor(((h)/60)*b); red=b;grn=color;blu=0; } else if(h<120) { color=Math.floor(((h-60)/60)*b); red=b-color;grn=b;blu=0; } else if(h<180) { color=Math.floor(((h-120)/60)*b); red=0;grn=b;blu=color; } else if(h<240) { color=Math.floor(((h-180)/60)*b); red=0;grn=b-color;blu=b; } else if(h<300) { color=Math.floor(((h-240)/60)*b); red=color;grn=0;blu=b; } else { color=Math.floor(((h-300)/60)*b); red=b;grn=0;blu=b-color; } h+=this.hInc; this.span.childNodes[i].style.color="rgb("+red+", "+grn+", "+blu+")"; } this.hue+=this.hspd; } // End --> </script> |
2. Pasang kode berikut pada bagian kamu akan memunculkan tulisan pelanginya
Salin kode JAVASCRIPT
1 2 3 4 5 6 7 8 | <div align="center"> <h4 id="r1">Tulisan pelangi</h4> </div> <script type="text/javascript"> var r1=document.getElementById("r1"); //get span to apply rainbow var myRainbowSpan=new RainbowSpan(r1, 0, 360, 255, 50, 18); //apply static rainbow effect myRainbowSpan.timer=window.setInterval("myRainbowSpan.moveRainbow()", myRainbowSpan.speed); </script> |
Selamat mencoba..!!

memuat halaman
iklan




Postingan yang lain:




Gak bIsa Massssss
gak bisa gmn nih?
gak muncul tulisannya apa gak muncul warnanya?
mas pada point kedua itu maksudnya pada bagian yang mana ?
terima kasih…
gak muncul warnanya….
saat posting, gunakan tab html
point yg kedua itu dipasang dipostingan/artikel blog kamu
wah mas aq masih blum ngerti…
haha maklum lah…
thx atas infonya,kunjung balik blogku,di:
http://mustofa-symbian.blogspot.com
ok, meluncur ke tkp
kk artikel blog ada di mana nya ???
cari di kategori..
Great site. A lot of useful information here. I’m sending it to some friends!
thanks infonya mas . kunjungi blogku mas adibima.co.cc/2011/01/add-ons-mozilla-firefox-anti-fake-login.html
Terima kasih atas informasinya. Sekali mencoba pasti bisa
pasangnya nya di elemen baru or di edit HTML
pasang di elemen / gadget juga bisa…
Mantap… trimakasih gan ane mw coba tuh