NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hero.vue 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template lang="pug">
  2. .hero.w-max.f-col(v-if="showHero")
  3. .tint
  4. .hero--video.w-max(v-if="heroType === 'video'")
  5. iframe(
  6. v-if="isPlaying"
  7. :src="`https://www.youtube.com/embed/${heroIdFromUrl}?autoplay=1`"
  8. frameborder="0"
  9. allowfullscreen
  10. ).embedded.w-max
  11. .blank.f-col(v-else)
  12. .hero--image--overlay.w-max.f-col
  13. h2.t-up.t-cntr(v-if="heroText") {{ heroText }}
  14. img.w-max(:src="getThumbnailFromYt(showHero)" alt="hero alt image")
  15. button(v-if="showPlaybutton" @click="isPlaying = true")
  16. .hero--image.w-max(v-else-if="heroType === 'image'")
  17. .hero--image--overlay.w-max.f-col
  18. h2.t-up.t-cntr(v-html="heroText")
  19. img.w-max(:src="showHero" alt="hero alt image")
  20. .hero--image(v-else)
  21. .hero--image--overlay.w-max.f-col
  22. div(v-html="heroText")
  23. //- if not hero image then heading overlay to show only in main article
  24. </template>
  25. <script>
  26. import { ytThumbnail } from '@/utils/helpers'
  27. import { mapState } from 'vuex'
  28. export default {
  29. data() {
  30. return {
  31. heroHeight: 0,
  32. isPlaying: false,
  33. }
  34. },
  35. computed: {
  36. ...mapState({
  37. showHero: state => state.hero.url,
  38. heroText: state => state.hero.text,
  39. heroType: state => state.hero.type,
  40. showPlaybutton: state => state.hero.playbutton,
  41. }),
  42. heroIdFromUrl() {
  43. const url = this.showHero.split('/')
  44. return url.pop()
  45. },
  46. },
  47. methods: {
  48. onResize() {
  49. this.heroHeight = this.$el.offsetWidth / 1.8
  50. },
  51. getThumbnailFromYt(url) {
  52. return ytThumbnail(url, 'max')
  53. },
  54. },
  55. mounted() {
  56. this.heroHeight = this.$el.offsetWidth / 1.8
  57. this.$nextTick(() => {
  58. window.addEventListener('resize', this.onResize)
  59. })
  60. },
  61. watch: {
  62. $route() {
  63. // console.log('remounting hero')
  64. // console.log(this.$store)
  65. // Clear the hero between pages
  66. this.$store.commit('CLEAR_HERO')
  67. },
  68. heroHeight() {
  69. if (!this.showHero) return
  70. Object.assign(this.$el.style, { height: this.heroHeight + 'px' })
  71. },
  72. },
  73. beforeUnmount() {
  74. window.removeEventListener('resize', this.onResize)
  75. },
  76. }
  77. </script>
  78. <style lang="postcss">
  79. // prettier-ignore
  80. @import './../sss/theme.sss'
  81. @import './../sss/variables.sss'
  82. .hero
  83. /* background-color: rebeccapurple */
  84. min-height: 25vh
  85. position: relative
  86. overflow: hidden
  87. .tint
  88. position: absolute
  89. height: 100%
  90. width: 100%
  91. background-color: #00000055
  92. &--image
  93. &--overlay
  94. /* color: $cia_white */
  95. position: absolute
  96. margin: 19% 0
  97. h2
  98. /* need better responsive solution for heading size */
  99. font-size: 3vw
  100. color: $cia_white
  101. text-shadow: 1px 1px $cia_black
  102. max-width: 70vw
  103. &--video
  104. width: 100vw
  105. height: 100%
  106. .embedded
  107. min-height: 25vh
  108. height: 100%
  109. .blank
  110. position: absolute
  111. height: inherit
  112. width: inherit
  113. button
  114. position: absolute
  115. min-height: $ms-7
  116. min-width: $ms-7
  117. background-color: rgba(170,17,0,0.4)
  118. border-radius: 50%
  119. border: 2px white solid
  120. &:hover
  121. border: 2px #DDD solid
  122. background-color: rgba(170,170,170,0.7)
  123. &:after
  124. content: ""
  125. position: absolute
  126. top: 20%
  127. left: 35%
  128. border-style: solid
  129. border-width: 1em 0 1em 1.6em
  130. border-color: transparent transparent transparent white
  131. @media (min-width: $medium)
  132. button
  133. height: $ms-9
  134. width: $ms-9
  135. border-width: 3px
  136. &:after
  137. top: 18%
  138. left: 30%
  139. border-width: 1.5em 0 1.5em 2.5em
  140. .hero .embedded
  141. min-height: 70vh
  142. </style>