Jquery Color Example - Jquery

How to change background color using jquery functions?

Snippet Code


  
Rate this page :
  [ 0 votes]

Jquery color code used to transform multiple colors for background. This color change occurs by dragging your mouse over the colors. Here the simple jquery color code to create and set color for background.

<script type="text/javascript"> function clicked(gg,rr,bb) { var hex='#'+deciToHex(gg)+deciToHex(rr)+deciToHex(bb); document.body.style.backgroundColor=hex; $("#tbprev").css('background-color',hex); } function getHexNum(num) { ar1=new Array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15'); ar2=new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); if(num>15) return num; else { red=ar2[num]; return red; } } function deciToHex(arg) { res2=999; args=arg; while(args>15) { arg1=parseInt(args/16); arg2=args%16; arg2=getHexNum(arg2); args=arg1; if(res2==999) res2=arg2.toString(); else res2=arg2.toString()+res2.toString(); } if(args<16 amp&res2 != 999) { def=getHexNum(args); res2=def+res2.toString(); } else if(res2==999) { if(args<16) res2=getHexNum(args); else res2=1; } if(res2.length==1) res2="0"+res2; return res2; } function change() { document.body.style.backgroundColor='white'; $("#tbprev").css('background-color','white'); } </script> <style type="text/css"> .tab{border: 1px inset black; background-color: black;} </style> <form name=colchanger> <table style="width:100%;" id='tbprev'> <tr><td> <table class=tab cellpadding=0 cellspacing=0> <script type="text/javascript"> for(i=0;i<=256;i+=18) { if(i==252) i=255; document.write("<tr>"); for(j=0;j<=256;j=j+51) { for(k=0;k<=256;k=k+51) { document.write("<td onMouseOver='clicked("+i+","+j+","+k+")' \ onMouseOut='change()'\ style=\"border: 1px inset black; width:15px; \ height: 15px; font-size: 6px; background-color: rgb("+i+","+j+","+k+");\""+"> </td>"); } } document.write("</tr>"); } </script> </table> </td></tr></table> </form>

Tags


Ask Questions

Ask Question