index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div id="kangri" class="kangri">
  3. <div class="kangricon">
  4. <span @click="(active -= 1), autoplay()" :class="{ noshow: active <= 0 }"
  5. >上一张</span
  6. >
  7. <video
  8. ref="video"
  9. autoplay
  10. loop
  11. x5-video-player-type="h5"
  12. x5-video-player-fullscreen="true"
  13. webkit-playsinline=""
  14. playsinline=""
  15. x5-playsinline=""
  16. crossorigin="anonymous"
  17. :key="active"
  18. >
  19. <source
  20. :src="require(`@/assets/videos/kangri/${videocon[active].video}`)"
  21. type="video/mp4"
  22. />
  23. </video>
  24. <span
  25. @click="(active += 1), autoplay()"
  26. :class="{ noshow: active >= videocon.length - 1 }"
  27. >下一张</span
  28. >
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. let videocon = [
  34. {
  35. id: "1",
  36. video: "1.mp4",
  37. },
  38. {
  39. id: "2",
  40. video: "2.mp4",
  41. },
  42. {
  43. id: "3",
  44. video: "3.mp4",
  45. },
  46. {
  47. id: "4",
  48. video: "4.mp4",
  49. },
  50. {
  51. id: "5",
  52. video: "5.mp4",
  53. },
  54. ];
  55. export default {
  56. data() {
  57. return {
  58. videocon,
  59. active: 0,
  60. };
  61. },
  62. methods: {
  63. changeVideo(item) {
  64. this.active = item.id;
  65. },
  66. autoplay() {
  67. this.$nextTick(() => {
  68. this.$refs.video.play();
  69. });
  70. },
  71. },
  72. mounted() {
  73. document.addEventListener(
  74. "WeixinJSBridgeReady",
  75. () => {
  76. this.autoplay();
  77. },
  78. false
  79. );
  80. window.player.on("autoplay", () => {
  81. this.autoplay();
  82. });
  83. },
  84. };
  85. </script>
  86. <style lang="less" scoped>
  87. .noshow {
  88. opacity: 0 !important;
  89. pointer-events: none !important;
  90. }
  91. .kangri {
  92. width: 100%;
  93. height: 100%;
  94. text-align: center;
  95. position: relative;
  96. pointer-events: none !important;
  97. .kangricon {
  98. height: 100%;
  99. width: 100%;
  100. color: #fff;
  101. display: flex;
  102. justify-content: center;
  103. pointer-events: none !important;
  104. align-items: center;
  105. > video {
  106. width: 50%;
  107. background-color: #000;
  108. height: 100%;
  109. pointer-events: auto;
  110. object-fit: fill;
  111. }
  112. > span {
  113. pointer-events: auto;
  114. display: inline-block;
  115. padding: 20px 60px;
  116. box-sizing: content-box;
  117. font-size: 40px;
  118. height: 50px;
  119. line-height: 50px;
  120. background: rgba(188, 21, 21, 0.9);
  121. border: 2px solid #dba761;
  122. border-radius: 77px;
  123. cursor: pointer;
  124. margin: 0 100px;
  125. &:hover,
  126. &.active {
  127. color: #dba761;
  128. }
  129. }
  130. }
  131. }
  132. </style>