123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <template>
- <view class="padding-tb barrage margin-top" :style="{bottom:bottom+'rpx',left:left+'rpx',backgroundColor:'#fcf5f5'}">
- <view class="text-lg text-bold linestyle" style="position: absolute;top: 20rpx;width: 100%;text-align: center;color:#fa3534;">
- 最新参与用户
- </view>
- <view class="flex flex-direction align-center justify-center">
- <transition-group name="barrage" class="">
- <view class="barrage-item" v-for="(item,index) in barrageList" :key="item.id">
- <!-- <image class="barrage-image" :src="item.image"></image> -->
- <view class="barrage-text" :style="{color:color,background:background,opacity:opacity}">
- <text>{{item.text}}</text>
- <text>{{item.phone}}</text>
- <text>{{item.time}}</text>
- </view>
- </view>
- </transition-group>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: "sinBarrage",
- props: {
- list: {
- type: Array || Object,
- default () {
- return {}
- }
- },
- rows: {
- type: Number,
- default: 3
- },
- color: {
- type: String,
- default: '#FFFFFF'
- },
- background: {
- type: String,
- default: '#000000'
- },
- opacity: {
- type: Number,
- default: 0.7
- },
- left: {
- type: Number,
- // default: 35
- },
- bottom: {
- type: Number,
- // default: 120
- },
- msec: {
- type: Number,
- default: 2000
- }
- },
- data() {
- return {
- barrageList: []
- }
- },
- created() {
- setInterval(() => {
- /** 此处逻辑:
- * 设定A数组为展示数组(默认3条数据),B数组为源数组(n条数据)
- * 首次进入页面,因A数组为空,所以根据rows设定每次从B数组头部取1条数据移入A数组尾部
- * 此后,在每个定时周期内,把A数组头部第1条数据移出来,并移入B数组尾部
- * 同时把B数组头部第1条数据移出来,并移入A数组尾部
- * 如此循环即可
- */
- if (this.barrageList.length < this.rows) {
- this.barrageList.push(this.list[0])
- this.list.splice(0, 1)
- } else {
- let objAFristItem = this.barrageList[0]
- this.barrageList.splice(objAFristItem, 1)
- this.list.push(objAFristItem)
- let objBFirstItem = this.list[0]
- this.list.splice(objBFirstItem, 1)
- this.barrageList.push(objBFirstItem)
- }
- }, this.msec)
- },
- watch: {
- }
- }
- </script>
- <style lang="scss">
- .barrage-item {
- transition: all 1s;
- }
-
- .barrage-enter {
- opacity: 0;
- transform: translateY(30px);
- }
- .barrage-leave-to {
- opacity: 0;
- transform: translateY(0px);
- }
- .barrage-enter-active {
- // position: absolute;
- }
- .barrage-leave-active {
- // transition: all .3s;
- }
- .linestyle::after{
- content: '';
- display: inline-block;
- width: 20rpx;
- height: 3rpx;
- background-color: #000;
- position: absolute;
- top: 20rpx;
- margin-left: 10rpx;
- }
- .linestyle::before{
- content: '';
- display: inline-block;
- width: 20rpx;
- height: 3rpx;
- background-color: #000;
- position: absolute;
- top: 20rpx;
- margin-left: -35rpx;
- }
- .barrage {
- // position: absolute;
- position: relative;
- height: 320rpx;
- display: flex;
- flex-direction: column;
- justify-content: flex-end;
- border-radius: 30rpx;
- width: 100%;
- box-shadow: 0 0 50rpx 0 rgba(0, 0, 0, 0.1);
- .barrage-item {
- margin-top: 10rpx;
- .barrage-image {
- display: inline-block;
- vertical-align: middle;
- width: 60rpx !important;
- height: 60rpx !important;
- margin-right: 10rpx;
- border-radius: 30rpx;
- }
- .barrage-text {
- font-size: 26rpx;
- // vertical-align: middle;
- color: #FFFFFF;
- padding: 10rpx 20rpx;
- border-radius: 30rpx;
- background: #000000;
- opacity: 0.7;
- display: flex;
- align-items: center;
- justify-content: space-around;
- width: 400rpx;
- }
- }
- }
- </style>
|