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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>取色</title> <script src="https://unpkg.com/vue"></script> <style type="text/css"> body{ text-align: center; } #colordiv{ width: 500px; height: 500px; margin: 0 auto; } input[type=range] { -webkit-appearance: none; width: 400px; border-radius: 10px; } input[type=range]::-webkit-slider-runnable-track { height: 15px; border-radius: 10px; box-shadow: 0 1px 1px #def3f8, inset 0 .125em .125em #0d1112; } input[type=range]:focus { outline: none; } input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 25px; width: 25px; margin-top: -5px; background: #ffffff; border-radius: 50%; border: solid 0.125em rgba(205, 224, 230, 0.5); box-shadow: 0 .125em .125em #3b4547; } </style> </head> <body> <div id="app"> <div id="colordiv" :style="color"></div> <br /><br /> 红色配比:{{ Math.floor( hong / 255 * 100) }}%<input v-model="hong" type="range" name="range" id="range" value="hong" max="255" step="1" :style="redcolor" /> <br /><br /> 绿色配比:{{ Math.floor( lv / 255 * 100) }}%<input v-model="lv" type="range" name="range" id="range" value="lv" max="255" step="1" :style="lvcolor"/> <br /><br /> 蓝色配比:{{ Math.floor( lan / 255 * 100) }}%<input v-model="lan" type="range" name="range" id="range" value="lan" max="255" step="1" :style="lancolor"/> </div> </body> <script type="text/javascript"> var div = document.getElementById('colordiv'); var app = new Vue({ el:'#app', data:{ hong:0, lv:0, lan:0, color:{ background:'black' }, redcolor:{ background: '-webkit-linear-gradient(red,red) no-repeat', backgroundSize:' 0% 100%' }, lvcolor:{ background: '-webkit-linear-gradient(green,green) no-repeat', backgroundSize:' 0% 100%' }, lancolor:{ background: '-webkit-linear-gradient(blue,blue) no-repeat', backgroundSize:'0% 100%' } }, methods:{ }, computed:{ change(){ this.color.background = "rgb(" + Number(this.hong) + ","+ Number(this.lv) +","+ Number(this.lan) +")"; this.redcolor.backgroundSize = Math.floor( this.hong / 255 * 100) + '% 100%'; this.lvcolor.backgroundSize = Math.floor( this.lv / 255 * 100) + '% 100%'; this.lancolor.backgroundSize = Math.floor( this.lan / 255 * 100) + '% 100%'; } }, updated(){ this.change } }) </script> </html>
|