js 背景调色板

叁歲伎倆 2021-07-24 17:10 401阅读 0赞
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title></title>
  5. <style>
  6. body{
  7. background-color:rgb(200,200,200)
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <p>
  13. <span>R:</span>
  14. <button class="rsub">-</button>
  15. <input type="text" class="rinput" placeholder="200" />
  16. <button class="radd">+</button>
  17. </p>
  18. <p>
  19. <span>G:</span>
  20. <button class="gsub">-</button>
  21. <input type="text" class="ginput" placeholder="200"/>
  22. <button class="gadd">+</button>
  23. </p>
  24. <p>
  25. <span>B:</span>
  26. <button class="bsub">-</button>
  27. <input type="text" class="binput" placeholder="200"/>
  28. <button class="badd">+</button>
  29. </p>
  30. <button class="go"></button>
  31. <script>
  32. var rsBtn=document.querySelector(".rsub");
  33. var rinput=document.querySelector(".rinput");
  34. var radd=document.querySelector(".radd");
  35. var gsBtn=document.querySelector(".gsub");
  36. var ginput=document.querySelector(".ginput");
  37. var gadd=document.querySelector(".gadd");
  38. var bsBtn=document.querySelector(".bsub");
  39. var binput=document.querySelector(".binput");
  40. var badd=document.querySelector(".badd");
  41. var go=document.querySelector(".go")
  42. /*定义信号量*/
  43. var r=200;
  44. var g=200;
  45. var b=200;
  46. rinput.value=r;
  47. ginput.value=g;
  48. binput.value=b;
  49. /*设置事件绑定*/
  50. /*红色绑定事件*/
  51. rsBtn.onclick=function(){
  52. /*校验范围*/
  53. r--;
  54. if(r<0)
  55. {
  56. r=0;
  57. }
  58. /*输入框值得改变*/
  59. rinput.value=r;
  60. /*背景颜色改变*/
  61. document.body.style.backgroundColor="rgb("+r+","+g+","+b+")";
  62. }
  63. radd.onclick=function(){
  64. r++;
  65. if(r>255)
  66. {
  67. r=255;
  68. }
  69. /*输入框值得改变*/
  70. rinput.value=r;
  71. /*背景颜色改变*/
  72. document.body.style.backgroundColor="rgb("+r+","+g+","+b+")";
  73. }
  74. /*绿色绑定事件*/
  75. gsBtn.onclick=function(){
  76. g--;
  77. if(g<0)
  78. {
  79. g=0;
  80. }
  81. /*输入框值得改变*/
  82. ginput.value=g;
  83. /*背景颜色改变*/
  84. document.body.style.backgroundColor="rgb("+r+","+g+","+b+")";
  85. }
  86. gadd.onclick=function(){
  87. g++;
  88. if(g>255)
  89. {
  90. g=255;
  91. }
  92. /*输入框值得改变*/
  93. ginput.value=g;
  94. /*背景颜色改变*/
  95. document.body.style.backgroundColor="rgb("+r+","+g+","+b+")";
  96. }
  97. /*蓝色绑定事件*/
  98. bsBtn.onclick=function(){
  99. b--;
  100. if(b<0)
  101. {
  102. b=0;
  103. }
  104. /*输入框值得改变*/
  105. binput.value=b;
  106. /*背景颜色改变*/
  107. document.body.style.backgroundColor="rgb("+r+","+g+","+b+")";
  108. }
  109. badd.onclick=function(){
  110. b++;
  111. if(b>255)
  112. {
  113. b=255;
  114. }
  115. /*输入框值得改变*/
  116. binput.value=b;
  117. /*背景颜色改变*/
  118. document.body.style.backgroundColor="rgb("+r+","+g+","+b+")";
  119. }
  120. go.onclick=function(){
  121. r=rinput.value;
  122. g=ginput.value;
  123. b=binput.value;
  124. if(r<0)
  125. {
  126. r=0;
  127. }
  128. if(r>255)
  129. {
  130. r=255;
  131. }
  132. if(g<0)
  133. {
  134. g=0;
  135. }
  136. if(g>255)
  137. {
  138. g=255;
  139. }
  140. if(b<0)
  141. {
  142. b=0;
  143. }
  144. if(b>255)
  145. {
  146. b=255;
  147. }
  148. rinput.value=r;
  149. ginput.value=g;
  150. binput.value=b;
  151. document.body.style.backgroundColor="rgb("+r+","+g+","+b+")";
  152. }
  153. </script>
  154. </body>
  155. </html>

发表评论

表情:
评论列表 (有 0 条评论,401人围观)

还没有评论,来说两句吧...

相关阅读

    相关 R语言调色板——colors()

    R语言中画图避免不了使用颜色,在R语言中也有很多颜色得包和函数,比如彩虹色、`rgb`、`colors`还有不同色系得调色板等等。今天我们使用`colors`来展示其中得`65