index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. loop
  10. controls="controls"
  11. autoplay
  12. x5-playsinline=""
  13. webkit-playsinline="true"
  14. playsinline="true"
  15. controlslist="nodownload"
  16. contextmenu="false"
  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. window.player.on("autoplay", () => {
  74. this.autoplay();
  75. });
  76. },
  77. };
  78. </script>
  79. <style lang="less" scoped>
  80. .noshow {
  81. opacity: 0 !important;
  82. pointer-events: none !important;
  83. }
  84. .kangri {
  85. width: 100%;
  86. height: 100%;
  87. text-align: center;
  88. position: relative;
  89. pointer-events: none !important;
  90. .kangricon {
  91. height: 100%;
  92. width: 100%;
  93. color: #fff;
  94. display: flex;
  95. justify-content: center;
  96. pointer-events: none !important;
  97. align-items: center;
  98. > video {
  99. width: 50%;
  100. background-color: #000;
  101. height: 100%;
  102. pointer-events: auto;
  103. object-fit: fill;
  104. }
  105. > span {
  106. pointer-events: auto;
  107. display: inline-block;
  108. padding: 20px 60px;
  109. box-sizing: content-box;
  110. font-size: 40px;
  111. height: 50px;
  112. line-height: 50px;
  113. background: rgba(188, 21, 21, 0.9);
  114. border: 2px solid #dba761;
  115. border-radius: 77px;
  116. cursor: pointer;
  117. margin: 0 100px;
  118. &:hover,
  119. &.active {
  120. color: #dba761;
  121. }
  122. }
  123. }
  124. }
  125. </style>