index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div
  3. @click="(e) => $emit('click', e)"
  4. class="linear-text"
  5. :style="linearTextStyle"
  6. :data-text="text"
  7. >
  8. {{ text }}
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. name: "LinearText",
  14. props: {
  15. text: {
  16. type: [Number, String],
  17. default: "",
  18. },
  19. fontSize: {
  20. type: String,
  21. default: "24px",
  22. },
  23. lineHeight: {
  24. type: String,
  25. default: "24px",
  26. },
  27. extClass: {
  28. type: Object,
  29. default: () => ({}),
  30. },
  31. startColor: {
  32. type: String,
  33. default: "#95CCFF",
  34. },
  35. endColor: {
  36. type: String,
  37. default: "#fff",
  38. },
  39. },
  40. computed: {
  41. linearTextStyle() {
  42. return {
  43. "--font-size": this.fontSize,
  44. "--line-height": this.lineHeight,
  45. "--start-color": this.startColor,
  46. "--end-color": this.endColor,
  47. ...this.extClass,
  48. };
  49. },
  50. },
  51. };
  52. </script>
  53. <style scoped>
  54. .linear-text {
  55. position: relative;
  56. color: var(--start-color);
  57. font-size: var(--font-size);
  58. line-height: var(--line-height);
  59. }
  60. .linear-text::after {
  61. content: attr(data-text);
  62. position: absolute;
  63. width: 100%;
  64. height: 100%;
  65. left: 0;
  66. top: 0;
  67. z-index: 1;
  68. color: var(--end-color);
  69. -webkit-mask: linear-gradient(180deg, var(--start-color), transparent);
  70. }
  71. </style>