ButtonGroupItem.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <script>
  2. export default {
  3. name: "ButtonGroupItem",
  4. data() {
  5. return {
  6. checked: true,
  7. height: 0,
  8. width: 0,
  9. };
  10. },
  11. emits: ["ClickItem"],
  12. computed: {
  13. buttonGroupItem() {
  14. return {
  15. "--height": `${this.height}px`,
  16. "--width": `${this.width}px`,
  17. };
  18. },
  19. },
  20. methods: {
  21. check() {
  22. this.checked = true;
  23. },
  24. uncheck() {
  25. this.checked = false;
  26. },
  27. },
  28. mounted() {
  29. const dom = this.$refs.buttonGroupItem;
  30. this.height = dom.clientHeight;
  31. this.width = dom.clientWidth;
  32. },
  33. };
  34. </script>
  35. <template>
  36. <div
  37. @click="(e) => $emit('click', e)"
  38. :class="{
  39. 'button-group_item': true,
  40. checked: checked,
  41. }"
  42. ref="buttonGroupItem"
  43. :style="buttonGroupItem"
  44. >
  45. <slot />
  46. </div>
  47. </template>
  48. <style scoped lang="less">
  49. .button-group_item {
  50. position: relative;
  51. padding: 8px 20px 2px 20px;
  52. font-size: 14px;
  53. box-sizing: border-box;
  54. cursor: pointer;
  55. margin-right: 5px;
  56. &.checked,
  57. &:hover {
  58. background: linear-gradient(360deg, #0094ff10 0%, #0094ff60 100%);
  59. border-radius: 5px;
  60. &::after {
  61. content: "";
  62. position: absolute;
  63. top: 0px;
  64. left: 0px;
  65. padding: 1px;
  66. box-sizing: border-box;
  67. border-radius: 5px;
  68. width: var(--width);
  69. height: var(--height);
  70. background: linear-gradient(
  71. 360deg,
  72. rgba(0, 163, 255, 0) 0%,
  73. #0c5a87 100%
  74. );
  75. /* 随便定义颜色 */
  76. --mask-bg: linear-gradient(red, red);
  77. --m-o: content-box, padding-box;
  78. /* mask允许使用者通过遮罩或者裁切特定区域的图片的方式来隐藏一个元素的部分或者全部可见区域 */
  79. /* 设置了用作元素蒙版层的图像,默认值为none,值为透明图片,或透明渐变 */
  80. -webkit-mask-image: var(--mask-bg), var(--mask-bg);
  81. /* 默认值为border-box,可选值与background-origin相同 */
  82. -webkit-mask-origin: var(--m-o);
  83. /* 默认值为border-box,可选值与background-clip相同 */
  84. -webkit-mask-clip: var(--m-o);
  85. /* exclude排除,只显示不重合的地方,Firefox支持4个属性 */
  86. mask-composite: exclude;
  87. /*只显示下方遮罩,重合的地方不显示*/
  88. -webkit-mask-composite: destination-out;
  89. pointer-events: none;
  90. }
  91. }
  92. }
  93. </style>