Sekarang seperti biasa, mari kita buat link secara pelangi (walau sudah usang) dan membikin tulisan rainbow secara Javascript b-)
Script For Link Rainbow
<script type='text/javascript'>//<![CDATA[
function doRainbow(a){act==0&&(act=1,a?objActive=a:objActive=event.srcElement,clrOrg=objActive.style.color,TimerID=setInterval("ChangeColor()",100))}function stopRainbow(){act&&(objActive.style.color=clrOrg,clearInterval(TimerID),act=0)}function doRainbowAnchor(){if(act==0){var a=event.srcElement;while(a.tagName!="A"&&a.tagName!="BODY"){a=a.parentElement;if(a.tagName=="A"||a.tagName=="BODY")break}a.tagName=="A"&&a.href!=""&&(objActive=a,act=1,clrOrg=objActive.style.color,TimerID=setInterval("ChangeColor()",100))}}function stopRainbowAnchor(){act&&objActive.tagName=="A"&&(objActive.style.color=clrOrg,clearInterval(TimerID),act=0)}function Mozilla_doRainbowAnchor(a){if(act==0){obj=a.target;while(obj.nodeName!="A"&&obj.nodeName!="BODY"){obj=obj.parentNode;if(obj.nodeName=="A"||obj.nodeName=="BODY")break}obj.nodeName=="A"&&obj.href!=""&&(objActive=obj,act=1,clrOrg=obj.style.color,TimerID=setInterval("ChangeColor()",100))}}function Mozilla_stopRainbowAnchor(a){act&&objActive.nodeName=="A"&&(objActive.style.color=clrOrg,clearInterval(TimerID),act=0)}function ChangeColor(){objActive.style.color=makeColor()}function makeColor(){return elmS==0?(elmR=elmV,elmG=elmV,elmB=elmV):
(t1=elmV,t2=(255-elmS)*elmV/255,t3=elmH%60,t3=(t1-t2)*t3/60,elmH<60?(elmR=t1,elmB=t2,elmG=t2+t3):elmH<120?(elmG=t1,elmB=t2,elmR=t1-t3):elmH<180?(elmG=t1,elmR=t2,elmB=t2+t3):elmH<240?(elmB=t1,elmR=t2,elmG=t1-t3):elmH<300?(elmB=t1,elmG=t2,elmR=t2+t3):elmH<360?(elmR=t1,elmG=t2,elmB=t1-t3): (elmR=0,elmG=0,elmB=0)),elmR=Math.floor(elmR).toString(16),elmG=Math.floor(elmG).toString(16),elmB=Math.floor(elmB).toString(16),elmR.length==1&&(elmR="0"+elmR),elmG.length==1&&(elmG="0"+elmG),elmB.length==1&&(elmB="0"+elmB),elmH=elmH+rate,elmH>=360&&(elmH=0),"#"+elmR+elmG+elmB}var rate=50;document.getElementById&&(window.onerror=new Function("return true"));var objActive,act=0,elmH=0,elmS=128,elmV=255,clrOrg,TimerID;document.all?(document.onmouseover=doRainbowAnchor,document.onmouseout=stopRainbowAnchor): document.getElementById&&(document.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT),document.onmouseover=Mozilla_doRainbowAnchor,document.onmouseout=Mozilla_stopRainbowAnchor)
//]]></script>
Setiap anchor link secara otomatis bersinar-sinar pelangi ketika disorot.function doRainbow(a){act==0&&(act=1,a?objActive=a:objActive=event.srcElement,clrOrg=objActive.style.color,TimerID=setInterval("ChangeColor()",100))}function stopRainbow(){act&&(objActive.style.color=clrOrg,clearInterval(TimerID),act=0)}function doRainbowAnchor(){if(act==0){var a=event.srcElement;while(a.tagName!="A"&&a.tagName!="BODY"){a=a.parentElement;if(a.tagName=="A"||a.tagName=="BODY")break}a.tagName=="A"&&a.href!=""&&(objActive=a,act=1,clrOrg=objActive.style.color,TimerID=setInterval("ChangeColor()",100))}}function stopRainbowAnchor(){act&&objActive.tagName=="A"&&(objActive.style.color=clrOrg,clearInterval(TimerID),act=0)}function Mozilla_doRainbowAnchor(a){if(act==0){obj=a.target;while(obj.nodeName!="A"&&obj.nodeName!="BODY"){obj=obj.parentNode;if(obj.nodeName=="A"||obj.nodeName=="BODY")break}obj.nodeName=="A"&&obj.href!=""&&(objActive=obj,act=1,clrOrg=obj.style.color,TimerID=setInterval("ChangeColor()",100))}}function Mozilla_stopRainbowAnchor(a){act&&objActive.nodeName=="A"&&(objActive.style.color=clrOrg,clearInterval(TimerID),act=0)}function ChangeColor(){objActive.style.color=makeColor()}function makeColor(){return elmS==0?(elmR=elmV,elmG=elmV,elmB=elmV):
(t1=elmV,t2=(255-elmS)*elmV/255,t3=elmH%60,t3=(t1-t2)*t3/60,elmH<60?(elmR=t1,elmB=t2,elmG=t2+t3):elmH<120?(elmG=t1,elmB=t2,elmR=t1-t3):elmH<180?(elmG=t1,elmR=t2,elmB=t2+t3):elmH<240?(elmB=t1,elmR=t2,elmG=t1-t3):elmH<300?(elmB=t1,elmG=t2,elmR=t2+t3):elmH<360?(elmR=t1,elmG=t2,elmB=t1-t3): (elmR=0,elmG=0,elmB=0)),elmR=Math.floor(elmR).toString(16),elmG=Math.floor(elmG).toString(16),elmB=Math.floor(elmB).toString(16),elmR.length==1&&(elmR="0"+elmR),elmG.length==1&&(elmG="0"+elmG),elmB.length==1&&(elmB="0"+elmB),elmH=elmH+rate,elmH>=360&&(elmH=0),"#"+elmR+elmG+elmB}var rate=50;document.getElementById&&(window.onerror=new Function("return true"));var objActive,act=0,elmH=0,elmS=128,elmV=255,clrOrg,TimerID;document.all?(document.onmouseover=doRainbowAnchor,document.onmouseout=stopRainbowAnchor): document.getElementById&&(document.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT),document.onmouseover=Mozilla_doRainbowAnchor,document.onmouseout=Mozilla_stopRainbowAnchor)
//]]></script>
Bila pada text mau dibikin berwarna-warni pake JavaScript, ini bumbunya.
<script type='text/javascript'>//<![CDATA[
function rt_decodeHex (a){var b=parseInt(a.substr(1,2),16),c=parseInt(a.substr(3,2),16),d=parseInt(a.substr(5,2),16);return[b,c,d]}function rt_encodeHex (a,b,c){var d="#";return d+=a<16?"0"+a.toString(16):a.toString(16),d+=b<16?"0"+b.toString(16):b.toString(16),d+=c<16?"0"+c.toString(16):c.toString(16),d}function rt_getColor(a){var b=15,c=255/b,d,e,f;return a<b?(d=255,e=a*c,f=0):a<2*b?(d=255-(a-b)*c,e=255,f=0):a<3*b?(d=0,e=255,f=(a-2*b)*c):a<4*b?(d=0,e=255-(a-3*b)*c,f=255):a<5*b?(d=(a-4*b)*c,e=0,f=255): (d=255,e=0,f=255-(a-5*b)*c),rt_encodeHex (d,e,f)}function rt_loadColor(a){var b=a.innerHTML,c=b.length,d=90/c;for(var e=c-1;e>=0;e--){var f=Math.round(d*e),g=rt_getColor(f);b=b.substr(0,e)+"<span style='color:"+g+"'>"+b.substr(e,1)+"</span>"+b.substr(e+1)}a.innerHTML=b}function rt_scriptStart(){var a=document.getElementsByTagName("span");for(var b=0;b<a.length;b++){var c=a[b];c.className=="rainbow"&&rt_loadColor(c)}}var rt_windowOnLoad=window.onload;window.onload=function(){rt_windowOnLoad!=undefined&&rt_windowOnLoad(),rt_scriptStart()}
//]]></script>
Pemakaiannya hanya tinggal membubuhi tagging sbbfunction rt_decodeHex (a){var b=parseInt(a.substr(1,2),16),c=parseInt(a.substr(3,2),16),d=parseInt(a.substr(5,2),16);return[b,c,d]}function rt_encodeHex (a,b,c){var d="#";return d+=a<16?"0"+a.toString(16):a.toString(16),d+=b<16?"0"+b.toString(16):b.toString(16),d+=c<16?"0"+c.toString(16):c.toString(16),d}function rt_getColor(a){var b=15,c=255/b,d,e,f;return a<b?(d=255,e=a*c,f=0):a<2*b?(d=255-(a-b)*c,e=255,f=0):a<3*b?(d=0,e=255,f=(a-2*b)*c):a<4*b?(d=0,e=255-(a-3*b)*c,f=255):a<5*b?(d=(a-4*b)*c,e=0,f=255): (d=255,e=0,f=255-(a-5*b)*c),rt_encodeHex (d,e,f)}function rt_loadColor(a){var b=a.innerHTML,c=b.length,d=90/c;for(var e=c-1;e>=0;e--){var f=Math.round(d*e),g=rt_getColor(f);b=b.substr(0,e)+"<span style='color:"+g+"'>"+b.substr(e,1)+"</span>"+b.substr(e+1)}a.innerHTML=b}function rt_scriptStart(){var a=document.getElementsByTagName("span");for(var b=0;b<a.length;b++){var c=a[b];c.className=="rainbow"&&rt_loadColor(c)}}var rt_windowOnLoad=window.onload;window.onload=function(){rt_windowOnLoad!=undefined&&rt_windowOnLoad(),rt_scriptStart()}
//]]></script>
<span class="rainbow"> YOUR BLAH BLEH BLOH HERE </span>
Otomatis tulisan yg ditag dengan itu akan terlihat Alhamdulillaah Yaaa...NB:
Usahakan letakkan JavaScript terlebih dahulu dicoba diatas tag </body> Jika tidak jalan, maka cobat diatas tag </head> Kalau mau dihostingkan itu lebih baik.
Selamat berkreasi, semoga bermanfaat :)Karena waktu dipostingkan script ada bentrok dengan kode emoticon, silahkan unduh disini kedua script diatas :)) Download Script All About Rainbow
http://farixsantips.blogspot.com/2011/11/rainbow-text-with-javascript.html
http://farixsantips.blogspot.com/2011/11/rainbow-text-with-javascript-part-2.html
Happy rainbow beleketek \m/
Tidak ada komentar:
Posting Komentar