lff-barrage.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view style="overflow: hidden;position: absolute;width: 100%;height: 100%;pointer-events: none; top: 0;">
  3. <view class="danmu-li" v-for="(item,index) in listData" :class="item.type" :style="item.style" :key="index">
  4. <!-- <view class="danmu-inner">
  5. <view class="user-box">
  6. <view class="user-img">
  7. <view class="img-box">
  8. <image :src="item.avatar" mode="aspectFit"></image>
  9. </view>
  10. </view>
  11. <view class="user-text cl1">
  12. {{item.username}}
  13. </view>
  14. <view class="user-status cl1">
  15. 抽中了 {{item.goods_name}}
  16. </view>
  17. </view>
  18. </view> -->
  19. <!-- 飘屏项start -->
  20. <view class="pp-item">
  21. <view class="avatar">
  22. <image :src="item.avatar" mode=""></image>
  23. </view>
  24. <view class="text-view">
  25. <text class="username">{{item.username}}</text>
  26. <text class="goods-name">抽中了 {{item.goods_name}}</text>
  27. </view>
  28. </view>
  29. <!-- 飘屏项end -->
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. props: {
  36. //rightToLeft leftToRight leftBottom
  37. type: {
  38. type: String,
  39. default: 'rightToLeft'
  40. },
  41. list: {
  42. type: Array,
  43. default () {
  44. return []
  45. }
  46. },
  47. minTime: {
  48. type: Number,
  49. default: 4
  50. },
  51. maxTime: {
  52. type: Number,
  53. default: 9
  54. },
  55. minTop: {
  56. type: Number,
  57. default: 0
  58. },
  59. maxTop: {
  60. type: Number,
  61. default: 240
  62. },
  63. hrackH: { //轨道高度
  64. type: Number,
  65. default: 40
  66. }
  67. },
  68. data() {
  69. return {
  70. listData: []
  71. }
  72. },
  73. mounted() {
  74. //leftBottom 使用参数
  75. if (this.type === 'leftBottom') {
  76. this.hrackNum = Math.floor(this.maxTop / this.hrackH);
  77. }
  78. },
  79. methods: {
  80. add(obj) {
  81. let data = {
  82. item: obj.item,
  83. goods_name: obj.goods_name,
  84. username: obj.username,
  85. avatar: obj.avatar,
  86. id:Date.parse(new Date()),
  87. time: Math.ceil(Math.floor(Math.random() * (this.maxTime - this.minTime + 1) + this.minTime)),
  88. type: this.type
  89. }
  90. if (this.type === 'leftBottom') {
  91. let objData = {
  92. item: data.item,
  93. goods_name: data.goods_name,
  94. username: data.username,
  95. avatar: data.avatar,
  96. type: 'leftBottomEnter',
  97. style: {
  98. transition: `all 0.5s`,
  99. animationDuration: `0.5s`,
  100. transform: `translateX(0%)`,
  101. bottom: `${this.minTop}px`
  102. }
  103. }
  104. let listLen = this.listData.length;
  105. let hrackNum = this.hrackNum;
  106. for (let i in this.listData) {
  107. if(this.listData[i].status === 'reuse'){ //重用
  108. this.$set(this.listData,i,objData);
  109. }else if(this.listData[i].status === 'reset'){ //重置
  110. this.listData[i].style.transition = 'none';
  111. this.listData[i].style.bottom = 0;
  112. this.listData[i].status = 'reuse';
  113. }else if(this.listData[i].status === 'recycle'){ //回收
  114. this.listData[i].type = 'leftBottomExit';
  115. this.listData[i].status = 'reset';
  116. }else{
  117. this.listData[i].style.bottom = parseInt(this.listData[i].style.bottom) + this.hrackH + 'px';
  118. }
  119. if(parseInt(this.listData[i].style.bottom) >= (this.maxTop - this.hrackH) && this.listData[i].status !== 'reset'){ //需要回收
  120. this.listData[i].status = 'recycle';
  121. }
  122. }
  123. if(listLen < hrackNum + 2){
  124. this.listData.push(objData);
  125. }
  126. } else if (this.type === 'rightToLeft') {
  127. let objData = {
  128. item: data.item,
  129. goods_name: data.goods_name,
  130. username: data.username,
  131. avatar: data.avatar,
  132. type: 'rightToLeft',
  133. style: {
  134. animationDuration: `${data.time}s`,
  135. top: `${Math.ceil(Math.random() * (this.maxTop - this.minTop + 1) + this.minTop)}px`
  136. },
  137. delTime: Date.parse(new Date()) + data.time * 1200
  138. }
  139. for (let i in this.listData) {
  140. if (this.listData[i].delTime <= Date.parse(new Date())) {
  141. this.repaint(i, objData.type);
  142. objData.type = '';
  143. this.$set(this.listData, i, objData);
  144. return
  145. }
  146. }
  147. this.listData.push(objData);
  148. }
  149. },
  150. repaint(index, type) {
  151. setTimeout(() => {
  152. this.listData[index].type = type;
  153. }, 100)
  154. }
  155. }
  156. }
  157. </script>
  158. <style>
  159. </style>
  160. <style lang="scss">
  161. @keyframes leftBottomEnter {
  162. 0% {
  163. transform: translateY(100%);
  164. opacity: 0;
  165. }
  166. 100% {
  167. transform: translateY(0%);
  168. opacity: 1;
  169. }
  170. }
  171. @keyframes leftBottomExit {
  172. 0% {
  173. transform: translateY(0%);
  174. opacity: 1;
  175. }
  176. 100% {
  177. transform: translateY(-200%);
  178. opacity: 0;
  179. }
  180. }
  181. @keyframes leftToRight {
  182. 0% {
  183. transform: translateX(-100%);
  184. }
  185. 100% {
  186. transform: translateX(100%);
  187. }
  188. }
  189. @keyframes rightToLeft {
  190. 0% {
  191. transform: translateX(100%);
  192. }
  193. 100% {
  194. transform: translateX(-100%);
  195. }
  196. }
  197. .danmu-li {
  198. position: absolute;
  199. width: 100%;
  200. transform: translateX(100%);
  201. animation-timing-function: linear;
  202. &.leftBottomEnter {
  203. animation-name: leftBottomEnter;
  204. }
  205. &.leftBottomExit{
  206. animation-name: leftBottomExit;
  207. animation-fill-mode: forwards;
  208. }
  209. &.rightToLeft {
  210. animation-name: rightToLeft;
  211. }
  212. &.leftToRight {
  213. animation-name: rightToLeft;
  214. }
  215. .danmu-inner {
  216. display: inline-block;
  217. .user-box {
  218. display: flex;
  219. padding: 3rpx 40rpx 3rpx 10rpx;
  220. background: rgba(0, 0, 0, 0.3);
  221. border-radius: 32rpx;
  222. align-items: center;
  223. .user-img {
  224. .img-box {
  225. display: flex;
  226. image {
  227. width: 58rpx;
  228. height: 58rpx;
  229. background: rgba(55, 55, 55, 1);
  230. border-radius: 50%;
  231. }
  232. }
  233. }
  234. .user-status {
  235. margin-left: 10rpx;
  236. white-space: nowrap;
  237. font-size: 28rpx;
  238. font-weight: 400;
  239. color: rgba(255, 255, 255, 1);
  240. }
  241. .user-text {
  242. margin-left: 10rpx;
  243. // white-space: nowrap;
  244. font-size: 28rpx;
  245. font-weight: 400;
  246. width: 80rpx;
  247. color: rgba(255, 255, 255, 1);
  248. }
  249. }
  250. }
  251. }
  252. .pp-item {
  253. top: 40rpx;
  254. left: 40rpx;
  255. background-image: url(https://www.chaomangdao.com/image/box/pp@2x.png);
  256. background-position: center;
  257. background-repeat: no-repeat;
  258. background-size: 100% 100%;
  259. width: 434rpx;
  260. height: 40rpx;
  261. line-height: 40rpx;
  262. position: absolute;
  263. padding-left: 52rpx;
  264. .avatar {
  265. position: absolute;
  266. z-index: 2;
  267. left: -10rpx;
  268. top: 50%;
  269. transform: translateY(-50%);
  270. width: 44rpx;
  271. height: 44rpx;
  272. border-radius: 50%;
  273. border: 2rpx solid #FFF;
  274. background: #D8D8D8;
  275. overflow: hidden;
  276. }
  277. .text-view {
  278. .username {
  279. font-size: 24rpx;
  280. font-family: PingFangSC-Regular, PingFang SC;
  281. font-weight: 400;
  282. color: #FFC50F;
  283. line-height: 34rpx;
  284. margin-right: 22rpx;
  285. }
  286. .goods-name {
  287. font-size: 24rpx;
  288. font-family: PingFangSC-Regular, PingFang SC;
  289. font-weight: 400;
  290. color: #FFFFFF;
  291. line-height: 34rpx;
  292. }
  293. }
  294. }
  295. </style>