|
| 1 | +export default { |
| 2 | + example1: ` |
| 3 | +<template> |
| 4 | + <div> |
| 5 | + <vue-slider |
| 6 | + v-model="value" |
| 7 | + class="color-slider" |
| 8 | + :process="false" |
| 9 | + :tooltip="'always'" |
| 10 | + > |
| 11 | + <template v-slot:dot> |
| 12 | + <div class="custom-dot" :style="{ borderColor: color }"></div> |
| 13 | + </template> |
| 14 | + <template v-slot:tooltip> |
| 15 | + <div class="custom-tooltip" :style="{ backgroundColor: color }"></div> |
| 16 | + </template> |
| 17 | + </vue-slider> |
| 18 | + </div> |
| 19 | +</template> |
| 20 | +
|
| 21 | +<style> |
| 22 | + .color-slider .vue-slider-rail { |
| 23 | + background: linear-gradient(to right, |
| 24 | + rgb(255,0,0), |
| 25 | + rgb(255,255,0), |
| 26 | + rgb(0,255,0), |
| 27 | + rgb(0,255,255), |
| 28 | + rgb(0,0,255), |
| 29 | + rgb(255,0,255), |
| 30 | + rgb(255,0,0) |
| 31 | + ); |
| 32 | + } |
| 33 | + .color-slider .custom-dot { |
| 34 | + width: 100%; |
| 35 | + color: 100%; |
| 36 | + background-color: #fff; |
| 37 | + border: 2px solid #fff; |
| 38 | + } |
| 39 | + .color-slider .custom-tooltip { |
| 40 | + width: 24px; |
| 41 | + color: 24px; |
| 42 | + border-radius: 50%; |
| 43 | + } |
| 44 | +</style> |
| 45 | +
|
| 46 | +<script> |
| 47 | + module.exports = { |
| 48 | + components: { |
| 49 | + VueSlider |
| 50 | + }, |
| 51 | + data: function () { |
| 52 | + return { |
| 53 | + value: 0 |
| 54 | + } |
| 55 | + }, |
| 56 | + computed: { |
| 57 | + color () { |
| 58 | + var hue = ((this.value / 100) * 360).toFixed(0) |
| 59 | + var hex = this.hsl2Hex(hue, 100, 50) |
| 60 | + return hex |
| 61 | + } |
| 62 | + }, |
| 63 | + methods: { |
| 64 | + hsl2Rgb(h, s, l) { |
| 65 | + s = s / 100 |
| 66 | + l = l / 100 |
| 67 | + var c, x, m, rgb |
| 68 | + c = (1 - Math.abs(2 * l - 1)) * s |
| 69 | + x = c * (1 - Math.abs(((h / 60) % 2) - 1)) |
| 70 | + m = l - c / 2 |
| 71 | + if (h >= 0 && h < 60) rgb = [c, x, 0] |
| 72 | + if (h >= 60 && h < 120) rgb = [x, c, 0] |
| 73 | + if (h >= 120 && h < 180) rgb = [0, c, x] |
| 74 | + if (h >= 180 && h < 240) rgb = [0, x, c] |
| 75 | + if (h >= 240 && h < 300) rgb = [x, 0, c] |
| 76 | + if (h >= 300 && h <= 360) rgb = [c, 0, x] |
| 77 | +
|
| 78 | + return rgb.map(function (v) { |
| 79 | + return 255 * (v + m) | 0 |
| 80 | + }) |
| 81 | + }, |
| 82 | + rgb2Hex(r, g, b) { |
| 83 | + var rgb = b | (g << 8) | (r << 16) |
| 84 | + return '#' + (0x1000000 + rgb).toString(16).slice(1) |
| 85 | + }, |
| 86 | + hsl2Hex(h, s, l) { |
| 87 | + var rgb = this.hsl2Rgb(h, s, l) |
| 88 | + return this.rgb2Hex(rgb[0], rgb[1], rgb[2]) |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | +</script> |
| 93 | + `, |
| 94 | +} |
0 commit comments