Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinhaitao
taobao-mini-template
Commits
3870608b
Commit
3870608b
authored
Sep 03, 2021
by
黄韬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[feat]横向弹幕
parent
129ec776
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
80 deletions
+87
-80
Barrage.jsx
...omponents/_tb_comps/Barrage/HorizontalBarrage/Barrage.jsx
+66
-68
Barrage.module.less
...s/_tb_comps/Barrage/HorizontalBarrage/Barrage.module.less
+21
-12
No files found.
c_client/src/components/_tb_comps/Barrage/HorizontalBarrage/Barrage.jsx
View file @
3870608b
import
React
from
'react'
import
React
,
{
useState
,
useEffect
,
useCallback
,
useRef
}
from
'react'
import
{
View
,
Text
}
from
'@tarojs/components'
import
{
View
,
Text
}
from
'@tarojs/components'
import
styles
from
'./Barrage.module.less
'
import
Taro
from
'@tarojs/taro
'
class
Barrage
extends
React
.
Component
{
import
styles
from
'./Barrage.module.less'
constructor
(
props
)
{
super
(
props
)
// 页面数据存储
this
.
state
=
{
barrageWay
:
[],
barrageList
:
[]
}
this
.
timer
=
null
}
componentDidMount
()
{
const
Barrage
=
props
=>
{
this
.
createData
()
const
{
const
self
=
this
dataList
=
[
setTimeout
(()
=>
{
'1撒撒打算打算打算的'
,
self
.
addBarrageListObj
()
'2撒撒打算打算打算的'
,
},
200
)
'3撒撒打算打算打算的'
,
}
'4撒撒打算打算打算的'
,
'5撒撒打算打算打算的'
,
'3撒撒打算打算打算的'
,
'3撒撒打算打算打算的'
,
'3撒撒打算打算打算的'
,
'3撒撒打算打算打算的'
,
'3撒撒打算打算打算的'
,
'3撒撒打算打算打算的'
,
'3撒撒打算打算打算的'
],
interval
=
5000
,
width
=
500
,
trackCount
=
1
}
=
props
componentWillUnmount
()
{
const
[
barrageList
,
setBarrageList
]
=
useState
([])
clearInterval
(
this
.
timer
)
const
[
animationData
,
setAnimationData
]
=
useState
(
null
)
}
const
timer
=
useRef
(
null
)
const
nowIndex
=
useRef
(
0
)
createData
()
{
const
createData
=
()
=>
{
const
{
dataList
,
trackCount
=
1
}
=
this
.
props
const
Tracks
=
Array
.
from
({
length
:
trackCount
},
(
v
,
k
)
=>
(
k
+
1
)
*
40
-
40
)
const
Tracks
=
Array
.
from
(
// TODO 多轨道弹幕
{
length
:
trackCount
},
setBarrageList
(
(
v
,
k
)
=>
(
k
+
1
)
*
40
-
40
dataList
.
map
((
item
,
index
)
=>
({
)
this
.
setState
({
barrageList
:
dataList
.
map
((
item
,
index
)
=>
({
width
:
item
.
length
*
17
+
5
,
top
:
Tracks
[
index
<
Tracks
.
length
?
index
:
index
%
trackCount
],
top
:
Tracks
[
index
<
Tracks
.
length
?
index
:
index
%
trackCount
],
time
:
5
,
context
:
item
context
:
item
}))
}))
}
)
)
}
}
/* *
const
callback
=
useCallback
(()
=>
{
* 因为从后台获取到的是全部的数据,所以要把数据分开,让每条数据有先后之分
timer
.
current
=
setInterval
(()
=>
{
* 每隔一秒往barrageList 数组插入一条数据
setAnimationData
(
* */
Taro
.
createAnimation
()
addBarrageListObj
()
{
.
translateX
(
nowIndex
.
current
===
0
?
0
:
(
-
width
/
2
)
*
nowIndex
.
current
)
const
self
=
this
.
step
({
const
{
barrageList
,
barrageWay
}
=
this
.
state
duration
:
nowIndex
.
current
===
0
?
0
:
1000
let
i
=
0
})
this
.
timer
=
setInterval
(
function
()
{
.
export
()
barrageWay
.
push
(
barrageList
[
i
])
)
self
.
setState
({
if
(
nowIndex
.
current
<
barrageList
.
length
-
1
)
{
barrageWay
:
barrageWay
nowIndex
.
current
=
nowIndex
.
current
+
1
})
}
else
{
i
++
nowIndex
.
current
=
0
if
(
i
===
barrageList
.
length
-
1
)
{
if
(
self
.
props
.
Infinite
)
{
i
=
0
}
else
{
clearInterval
(
self
.
timer
)
}
}
}
},
1500
)
},
interval
+
1000
)
}
},
[
barrageList
,
width
])
useEffect
(()
=>
{
callback
()
return
()
=>
clearInterval
(
timer
.
current
)
},
[
callback
])
render
()
{
useEffect
(()
=>
{
const
{
barrageWay
}
=
this
.
state
createData
()
return
(
return
()
=>
{}
<
View
className=
{
styles
[
'barrage-fly'
]
}
>
},
[])
{
barrageWay
.
map
((
item
,
i
)
=>
{
if
(
!
item
?.
context
)
return
null
return
(
<
View
id=
'barrage_wrap'
style=
{
`width:${width / 100}rem`
}
className=
{
styles
[
'barrage-wrap'
]
}
>
<
View
id=
'barrage_container'
animation=
{
animationData
}
className=
{
styles
[
'barrage-fly'
]
}
>
{
barrageList
.
map
((
item
,
index
)
=>
{
return
(
return
(
<
View
<
View
id=
{
`barrage-${index}`
}
key=
{
index
}
style=
{
`width:${width / 100}rem`
}
className=
{
styles
[
'barrage-textFly'
]
}
>
key=
{
i
}
className=
{
styles
[
'barrage-textFly'
]
}
style=
{
`animation: ${styles.first} ${item.time}s linear forwards; top: ${item.top}px`
}
>
{
/* 弹幕内容 */
}
{
/* 弹幕内容 */
}
<
Text
className=
{
styles
[
'barrage-text'
]
}
>
{
item
.
context
}
</
Text
>
<
Text
className=
{
styles
[
'barrage-text'
]
}
>
{
item
.
context
}
</
Text
>
</
View
>
</
View
>
)
)
})
}
})
}
</
View
>
</
View
>
)
</
View
>
}
)
}
}
export
default
Barrage
export
default
Barrage
c_client/src/components/_tb_comps/Barrage/HorizontalBarrage/Barrage.module.less
View file @
3870608b
.barrage-wrap {
height: 64px;
border: 1px solid red;
overflow: hidden;
}
.barrage-fly {
.barrage-fly {
position: relative;
position: relative;
height: 100%;
height: 100%;
width: 700px;
z-index: 3;
z-index: 3;
display: flex;
}
.barrage-textFly {
.barrage-textFly {
position: absolute;
flex-shrink: 0;
height: 64px;
height: 64px;
line-height: 64px;
overflow: hidden;
color: #f9c797;
line-height: 64px;
font-size: 32px;
color: #f9c797;
padding-right: 30px;
font-size: 32px;
}
padding: 0 10px;
box-sizing: border-box;
text-align: center;
}
.barrage-text {
.barrage-text {
white-space: nowrap;
white-space: nowrap;
}
}
}
@keyframes first {
@keyframes first {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment