Danmaku.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <div class="danmaku-area">
  3. <div
  4. class="danmaku-container"
  5. v-chat-scroll
  6. v-if="isShowList"
  7. >
  8. <!-- <ul class=""> -->
  9. <transition-group appear tag="ul" class="danmaku-list" name="dm">
  10. <li
  11. class="danmaku-list-item"
  12. v-for="(item) in showDanmakuData"
  13. :key="item"
  14. >
  15. <span> {{ item }}</span>
  16. </li>
  17. </transition-group>
  18. </div>
  19. <div class="input-container" v-if="!isMobile">
  20. <span class="send-choices" @click.stop="toggleSelectMenu"
  21. >请选择弹幕内发送吧~</span
  22. >
  23. <div class="send-btn-container">
  24. <img
  25. @click="hideList"
  26. class="show-icon"
  27. :src="showIcon || ''"
  28. v-if="isShowList"
  29. />
  30. <img
  31. @click="showList"
  32. class="close-icon"
  33. :src="closeIcon || ''"
  34. v-if="!isShowList"
  35. />
  36. <button class="send-btn primary">发送</button>
  37. </div>
  38. <ul class="show-list" v-show="isShowSelectList">
  39. <li
  40. class="list-item"
  41. v-for="(item, key) in quotes"
  42. :key="key"
  43. @click="sendDanmaku(key)"
  44. >
  45. {{ item }}
  46. </li>
  47. </ul>
  48. </div>
  49. <div class="input-mobile" v-else>
  50. <span class="send-choices" @click.stop="toggleSelectMenu">请选择弹幕内发送吧~</span>
  51. <div class="send-btn-container">
  52. <img
  53. @click="hideList"
  54. class="show-icon"
  55. :src="showIcon || ''"
  56. v-if="isShowList"
  57. />
  58. <img
  59. @click="showList"
  60. class="close-icon"
  61. :src="closeIcon || ''"
  62. v-if="!isShowList"
  63. />
  64. <!-- <button class="send-btn">发送</button> -->
  65. </div>
  66. <ul class="show-list" v-show="isShowSelectList">
  67. <li
  68. class="list-item"
  69. v-for="(item, key) in quotes"
  70. :key="key"
  71. @click="sendDanmaku(key)"
  72. >
  73. {{ item }}
  74. </li>
  75. </ul>
  76. </div>
  77. </div>
  78. </template>
  79. <script>
  80. export default {
  81. name: "danmaku",
  82. props: {
  83. quotes: {
  84. type: Array,
  85. default: function() {
  86. return [
  87. ];
  88. },
  89. },
  90. showIcon: {
  91. type: String,
  92. required: true,
  93. },
  94. closeIcon: {
  95. type: String,
  96. required: true,
  97. },
  98. arrowIcon: {
  99. type: String,
  100. required: true,
  101. },
  102. limit: {
  103. type: Number,
  104. required: false,
  105. default: 5000,
  106. },
  107. },
  108. watch: {
  109. isNotInputAction: function() {},
  110. },
  111. data() {
  112. return {
  113. showDanmakuData: [],
  114. isShowList: true,
  115. isShowSelectList: false,
  116. isNotInputAction: false,
  117. timer: null,
  118. autoIndex: 0,
  119. isMobile: /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)
  120. };
  121. },
  122. methods: {
  123. toggleSelectMenu() {
  124. this.isShowSelectList = !this.isShowSelectList;
  125. },
  126. showList() {
  127. this.isShowList = true;
  128. },
  129. hideList() {
  130. this.isShowList = false;
  131. },
  132. sendDanmaku(index) {
  133. const text = this.quotes[index];
  134. if (this.showDanmakuData.length <= this.limit) {
  135. this.showDanmakuData.push(text);
  136. }
  137. this.isShowSelectList = false;
  138. this.isNotInputAction = true;
  139. },
  140. autoPopAnimation() {
  141. if (!this.isNotInputAction) {
  142. this.timer = setInterval(() => {
  143. if (this.autoIndex <= this.quotes.length) {
  144. if (this.quotes[this.autoIndex]) {
  145. this.showDanmakuData.push(this.quotes[this.autoIndex]);
  146. this.autoIndex++;
  147. } else {
  148. clearInterval(this.timer);
  149. }
  150. }
  151. }, 2000);
  152. }
  153. },
  154. },
  155. mounted() {
  156. this.autoPopAnimation();
  157. },
  158. };
  159. </script>
  160. <!-- Add "scoped" attribute to limit CSS to this component only -->
  161. <style scoped>
  162. .danmaku-area {
  163. margin: 0;
  164. }
  165. .danmaku-container {
  166. max-width: 340px;
  167. max-height: 288px;
  168. overflow-x: hidden;
  169. overflow-y: scroll;
  170. }
  171. /* .hidedanmu{
  172. visibility: hidden;
  173. pointer-events: none;
  174. } */
  175. .danmaku-list {
  176. text-decoration: none;
  177. max-width: 342px;
  178. overflow: hidden;
  179. display: flex;
  180. flex-direction: column;
  181. margin: 0;
  182. padding: 0;
  183. }
  184. .danmaku-list li.danmaku-list-item {
  185. margin-bottom: 10px;
  186. padding: 0;
  187. display: block;
  188. overflow: hidden;
  189. white-space: nowrap;
  190. text-overflow: ellipsis;
  191. text-align: left;
  192. }
  193. .danmaku-list li.danmaku-list-item > span {
  194. padding: 0 20px;
  195. line-height: 36px;
  196. font-size: 14px;
  197. display: inline-block;
  198. margin: 0;
  199. color: #fff;
  200. border-radius: 20px;
  201. background: rgba(0, 0, 0, 0.6);
  202. border: 1px solid hsla(0, 0%, 100%, 0.53);
  203. overflow: hidden;
  204. white-space: nowrap;
  205. text-overflow: ellipsis;
  206. text-align: left;
  207. max-width: 290px;
  208. }
  209. .danmaku-list li.danmaku-list-item:nth-last-child(6) {
  210. /* visibility: hidden; */
  211. animation: fadeout 0.3s linear;
  212. }
  213. .input-container {
  214. background: rgba(0, 0, 0, 0.6);
  215. border-radius: 25px;
  216. max-width: 350px;
  217. height: 48px;
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. position: relative;
  222. padding: 10px;
  223. }
  224. .input-container span {
  225. color: rgb(140, 140, 140);
  226. cursor: pointer;
  227. font-size: 14px;
  228. height: 48px;
  229. text-align: left;
  230. line-height: 48px;
  231. }
  232. .input-container > * {
  233. cursor: pointer;
  234. }
  235. .arrow-icon {
  236. margin-right: 8px;
  237. width: 18px;
  238. }
  239. .send-btn {
  240. background: rgb(184, 23, 23);
  241. color: #fff;
  242. padding: 5px 15px;
  243. border: 10px;
  244. outline: 0;
  245. font-size: 16px;
  246. cursor: pointer;
  247. border-radius: 15px;
  248. margin-left: 5px;
  249. }
  250. .send-btn:hover,
  251. .send-btn:focus {
  252. background: rgb(153, 17, 17);
  253. }
  254. .send-btn-container {
  255. display: flex;
  256. align-items: center;
  257. }
  258. .send-btn-container .show-icon,
  259. .send-btn-container .close-icon {
  260. width: 24px;
  261. margin-right: 4px;
  262. }
  263. .input-container .show-list {
  264. text-decoration: none;
  265. position: absolute;
  266. left: 0;
  267. bottom: 64px;
  268. background: rgba(0, 0, 0, 0.7);
  269. width: 340px;
  270. color: #fff;
  271. border-radius: 10px;
  272. max-height: 200px;
  273. overflow-x: hidden;
  274. overflow-y: scroll;
  275. margin: 0;
  276. padding: 0;
  277. }
  278. .input-container .show-list .list-item {
  279. text-align: left;
  280. font-size: 14px;
  281. line-height: 36px;
  282. text-decoration: none;
  283. white-space: nowrap;
  284. text-overflow: ellipsis;
  285. color: #fff;
  286. max-width: 100%;
  287. padding: 0 10px;
  288. overflow: hidden;
  289. }
  290. .input-container .show-list .list-item:hover {
  291. background: rgb(184, 23, 23);
  292. }
  293. .dm-enter {
  294. opacity: 0;
  295. transform: translateY(20px);
  296. }
  297. .dm-leave-to {
  298. opacity: 0;
  299. transform: translateY(-50px);
  300. }
  301. .dm-enter-active,
  302. .dm-leave-active {
  303. transition: all 0.6s ease;
  304. }
  305. .dm-move {
  306. transition: all 0.6s ease;
  307. }
  308. .dm-leave-active {
  309. position: absolute;
  310. }
  311. .input-mobile{
  312. min-width: 213px;
  313. height: 40px;
  314. background: rgba(0, 0, 0, 0.5);
  315. border-radius: 3px;
  316. display: flex;
  317. padding: 10px 10px 10px 20px;
  318. box-sizing: border-box;
  319. position: relative;
  320. justify-content: space-between;
  321. }
  322. .input-mobile .send-choices{
  323. color: #fff;
  324. font-size: 14px;
  325. display: inline-block;
  326. vertical-align: middle;
  327. line-height: 20px;
  328. }
  329. .input-mobile .show-list {
  330. text-decoration: none;
  331. position: absolute;
  332. left: 0;
  333. bottom: 50px;
  334. background: rgba(0, 0, 0, 0.9);
  335. width: 90%;
  336. color: #fff;
  337. border-radius: 3px;
  338. max-height: 200px;
  339. overflow-x: hidden;
  340. overflow-y: scroll;
  341. margin: 0;
  342. padding: 0;
  343. }
  344. .input-mobile .show-list .list-item {
  345. text-align: left;
  346. font-size: 14px;
  347. line-height: 36px;
  348. text-decoration: none;
  349. white-space: nowrap;
  350. text-overflow: ellipsis;
  351. color: #fff;
  352. max-width: 100%;
  353. padding: 0 10px;
  354. overflow: hidden;
  355. }
  356. .input-mobile .show-list .list-item:hover {
  357. background: rgb(184, 23, 23);
  358. }
  359. .input-mobile .send-btn-container{
  360. margin-left: 10px;
  361. }
  362. @keyframes fadeout {
  363. 0% {
  364. opacity: 1;
  365. transform: translateY(10px);
  366. }
  367. 50% {
  368. opacity: 0.7;
  369. transform: translateY(3px);
  370. }
  371. 100% {
  372. opacity: 0.2;
  373. transform: translateY(0px);
  374. }
  375. }
  376. @media only screen and (max-width: 500px), (max-height: 487px) {
  377. .danmaku-list li.danmaku-list-item{
  378. margin-bottom: 5px;
  379. }
  380. .danmaku-list li.danmaku-list-item > span{
  381. border-radius: 3px;
  382. border: 0;
  383. }
  384. }
  385. </style>