ImageTitleBlock.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div
  3. :class="[
  4. 'ImageTitleBlock',
  5. title ? 'has-title' : '',
  6. fit? 'fit' : ''
  7. ]"
  8. :style="{ backgroundImage: `url('${image || (title ? ImageFailed : '')}')` }"
  9. @click="$emit('click')"
  10. >
  11. <img
  12. v-if="image"
  13. :src="image"
  14. alt=""
  15. class="image"
  16. >
  17. <div class="desc">
  18. <h5>{{ title }}</h5>
  19. <p>{{ desc }}</p>
  20. </div>
  21. </div>
  22. </template>
  23. <script setup lang="ts">
  24. import ImageFailed from '@/assets/images/ImageFailed.png';
  25. defineProps({
  26. title: {
  27. type: String,
  28. default: ''
  29. },
  30. desc: {
  31. type: String,
  32. default: '' ,
  33. },
  34. image: {
  35. type: String,
  36. default: ''
  37. },
  38. fit: {
  39. type: Boolean,
  40. default: false
  41. },
  42. })
  43. defineEmits([
  44. 'click',
  45. ])
  46. </script>
  47. <style lang="scss">
  48. @use '@/assets/scss/colors.scss' as *;
  49. .ImageTitleBlock {
  50. position: relative;
  51. padding: 24px;
  52. background-size: cover;
  53. background-position: top center;
  54. width: 400px;
  55. height: 270px;
  56. margin-right: 24px;
  57. img {
  58. position: absolute;
  59. top: 0;
  60. left: 0;
  61. width: 100%;
  62. height: 100%;
  63. object-fit: contain !important;
  64. z-index: 1;
  65. }
  66. &.fit {
  67. width: 100%;
  68. margin-right: 0;
  69. }
  70. &.has-title {
  71. &::before {
  72. content: '';
  73. display: block;
  74. position: absolute;
  75. right: 0;
  76. left: 0;
  77. bottom: 0;
  78. height: 120px;
  79. z-index: 20;
  80. background: linear-gradient(
  81. 180deg,
  82. rgba(#000, 0) 0%,
  83. rgba(#000, 0.7) 100%
  84. )
  85. }
  86. }
  87. .desc {
  88. position: absolute;
  89. right: 0;
  90. left: 0;
  91. bottom: 0;
  92. display: flex;
  93. flex-direction: column;
  94. padding: 24px;
  95. color: #fff;
  96. z-index: 20;
  97. h5 {
  98. font-family: SourceHanSerifCNBold;
  99. font-size: 1.1rem;
  100. margin-bottom: 5px;
  101. }
  102. p {
  103. font-size: 0.8rem;
  104. margin: 0;
  105. }
  106. }
  107. }
  108. </style>