Posted By

misha on 12/05/09


Tagged


Versions (?)

Main Script


 / Published in: JavaScript
 

  1. <script type="text/javascript">
  2.  
  3.  
  4. // init code
  5. var r = new Slider(document.getElementById("red-slider"), document.getElementById("red-slider-input"));
  6. r.setMaximum(255);
  7. var g = new Slider(document.getElementById("green-slider"), document.getElementById("green-slider-input"));
  8. g.setMaximum(255);
  9. var b = new Slider(document.getElementById("blue-slider"), document.getElementById("blue-slider-input"));
  10. b.setMaximum(255);
  11.  
  12. var ri = document.getElementById("red-input");
  13. ri.onchange = function () {
  14. r.setValue(parseInt(this.value));
  15. };
  16.  
  17. var gi = document.getElementById("green-input");
  18. gi.onchange = function () {
  19. g.setValue(parseInt(this.value));
  20. };
  21.  
  22. var bi = document.getElementById("blue-input");
  23. bi.onchange = function () {
  24. b.setValue(parseInt(this.value));
  25. };
  26.  
  27. r.onchange = g.onchange = b.onchange = function () {
  28. var cr = document.getElementById("color-result");
  29. cr.style.backgroundColor = "rgb(" + r.getValue() + "," + g.getValue() + "," + b.getValue() + ")";
  30. rg.r = ri.value = r.getValue();
  31. rg.g = gi.value = g.getValue();
  32. rg.b = bi.value = b.getValue();
  33. rg2hs(rg);
  34. ud("0",rg);
  35. dom();
  36. if (typeof window.onchange == "function")
  37. window.onchange();
  38. };
  39.  
  40. r.setValue(128);
  41. g.setValue(128);
  42. b.setValue(128);
  43.  
  44. // end init
  45.  
  46. function setRgb(nRed, nGreen, nBlue) {
  47. r.setValue(nRed);
  48. g.setValue(nGreen);
  49. b.setValue(nBlue);
  50. }
  51.  
  52. function getRgb() {
  53. return {
  54. r: r.getValue(),
  55. g: g.getValue(),
  56. b: b.getValue()
  57. };
  58. }
  59.  
  60. function fixSize() {
  61. r.recalculate();
  62. g.recalculate();
  63. b.recalculate();
  64. }
  65.  
  66. window.onresize = fixSize;
  67.  
  68. fixSize();
  69.  
  70.  
  71. </script>

Report this snippet  

You need to login to post a comment.