index.vue 1.2 KB

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