Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
Z
zh_zcb-ems
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
chen.yiwen
zh_zcb-ems
Commits
f553889c
Commit
f553889c
authored
Sep 05, 2022
by
wu.hui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 动画改成js控制
parent
c48e51c7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
917 additions
and
216 deletions
+917
-216
stat-bar.css
src/css/stat-bar.css
+3
-96
index.html
src/index.html
+1
-0
index.js
src/js/index.js
+85
-49
tween.umd.js
src/js/tween.umd.js
+825
-0
stat-bar.less
src/less/stat-bar.less
+3
-71
No files found.
src/css/stat-bar.css
View file @
f553889c
...
@@ -48,9 +48,9 @@
...
@@ -48,9 +48,9 @@
margin-left
:
10px
;
margin-left
:
10px
;
}
}
.stat-bar
.stat-item
.scroll-num
{
.stat-bar
.stat-item
.scroll-num
{
width
:
var
(
--width
,
39px
)
;
width
:
39px
;
height
:
var
(
--height
,
50px
)
;
height
:
50px
;
line-height
:
var
(
--height
,
50px
)
;
line-height
:
50px
;
text-align
:
center
;
text-align
:
center
;
font-size
:
41px
;
font-size
:
41px
;
color
:
#01fff6
;
color
:
#01fff6
;
...
@@ -66,96 +66,3 @@
...
@@ -66,96 +66,3 @@
color
:
#758094
;
color
:
#758094
;
font-family
:
'Source Han Sans CN'
;
font-family
:
'Source Han Sans CN'
;
}
}
.stat-bar
.animate
{
-webkit-animation
:
move
calc
(
var
(
--duration
)
*
1s
)
calc
(
var
(
--delay
)
*
1s
)
linear
,
bounce-in-down
1s
calc
((
var
(
--duration
)
+
var
(
--delay
))
*
1s
)
forwards
;
animation
:
move
calc
(
var
(
--duration
)
*
1s
)
calc
(
var
(
--delay
)
*
1s
)
linear
,
bounce-in-down
1s
calc
((
var
(
--duration
)
+
var
(
--delay
))
*
1s
)
forwards
;
}
.stat-bar
.init
{
-webkit-transform
:
translateY
(
calc
(
var
(
--i
)
*
-9.09%
));
-ms-transform
:
translateY
(
calc
(
var
(
--i
)
*
-9.09%
));
transform
:
translateY
(
calc
(
var
(
--i
)
*
-9.09%
));
}
@-webkit-keyframes
move
{
from
{
-webkit-transform
:
translateY
(
calc
(
var
(
--i
)
*
-9.09%
));
transform
:
translateY
(
calc
(
var
(
--i
)
*
-9.09%
));
-webkit-filter
:
url(#blur)
;
filter
:
url(#blur)
;
}
to
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
));
-webkit-filter
:
url(#blur)
;
filter
:
url(#blur)
;
}
}
@keyframes
move
{
from
{
-webkit-transform
:
translateY
(
calc
(
var
(
--i
)
*
-9.09%
));
transform
:
translateY
(
calc
(
var
(
--i
)
*
-9.09%
));
-webkit-filter
:
url(#blur)
;
filter
:
url(#blur)
;
}
to
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
));
-webkit-filter
:
url(#blur)
;
filter
:
url(#blur)
;
}
}
@-webkit-keyframes
bounce-in-down
{
from
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
1%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
1%
));
-webkit-filter
:
none
;
filter
:
none
;
}
25
%
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
+
0.8%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
+
0.8%
));
}
50
%
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
1%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
1%
));
}
70
%
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
+
0.6%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
+
0.6%
));
}
85
%
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
0.3%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
0.3%
));
}
to
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
));
}
}
@keyframes
bounce-in-down
{
from
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
1%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
1%
));
-webkit-filter
:
none
;
filter
:
none
;
}
25
%
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
+
0.8%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
+
0.8%
));
}
50
%
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
1%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
1%
));
}
70
%
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
+
0.6%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
+
0.6%
));
}
85
%
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
0.3%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
-
0.3%
));
}
to
{
-webkit-transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
));
transform
:
translateY
(
calc
(
var
(
--j
)
*
-9.09%
));
}
}
src/index.html
View file @
f553889c
...
@@ -254,5 +254,6 @@
...
@@ -254,5 +254,6 @@
</body>
</body>
<script
src=
"https://cdn.ucyber.cn/common/echarts.js"
></script>
<script
src=
"https://cdn.ucyber.cn/common/echarts.js"
></script>
<script
src=
"./js/tween.umd.js"
></script>
<script
src=
"./js/index.js"
></script>
<script
src=
"./js/index.js"
></script>
</html>
</html>
\ No newline at end of file
src/js/index.js
View file @
f553889c
...
@@ -219,13 +219,11 @@ const lineChartOption = (xData, yData, interval) => {
...
@@ -219,13 +219,11 @@ const lineChartOption = (xData, yData, interval) => {
}
}
// 创建多组数字
// 创建多组数字
function
createMultiSrollNum
(
numArr
,
width
,
height
)
{
function
createMultiSrollNum
(
numArr
)
{
const
scrollBox
=
document
.
getElementsByClassName
(
'scroll-box'
)
const
scrollBox
=
document
.
getElementsByClassName
(
'scroll-box'
)
for
(
let
i
=
0
;
i
<
scrollBox
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
scrollBox
.
length
;
i
++
)
{
const
scrollNode
=
scrollBox
[
i
]
const
scrollNode
=
scrollBox
[
i
]
const
childNumArr
=
numArr
[
i
].
split
(
''
)
const
childNumArr
=
numArr
[
i
].
split
(
''
)
scrollNode
.
style
.
setProperty
(
'--width'
,
width
+
'px'
)
scrollNode
.
style
.
setProperty
(
'--height'
,
height
+
'px'
)
const
docFrag
=
document
.
createDocumentFragment
()
const
docFrag
=
document
.
createDocumentFragment
()
childNumArr
.
forEach
((
num
,
i
)
=>
{
childNumArr
.
forEach
((
num
,
i
)
=>
{
docFrag
.
appendChild
(
createSrollNum
(
num
))
docFrag
.
appendChild
(
createSrollNum
(
num
))
...
@@ -250,63 +248,95 @@ function createSrollNum(num) {
...
@@ -250,63 +248,95 @@ function createSrollNum(num) {
<li>8</li>
<li>8</li>
<li>9</li>
<li>9</li>
<li>0</li>
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>`
</ul>`
const
ulNode
=
scrollNumNode
.
childNodes
[
0
]
const
ulNode
=
scrollNumNode
.
childNodes
[
0
]
ulNode
.
setAttribute
(
ulNode
.
setAttribute
(
'style'
,
'transform: translateY('
+
num
*
-
5
+
'%)'
)
'style'
,
'transform: translateY('
+
num
*
-
9.09
+
'%)'
)
return
scrollNumNode
return
scrollNumNode
}
}
// 创建多组数字动画
// 创建多组数字动画
function
addMultiDigitAnimate
(
beforeNumArr
,
afterNumArr
,
delays
,
numArr
)
{
function
addMultiDigitAnimate
(
beforeNumArr
,
afterNumArr
)
{
TWEEN
.
removeAll
()
console
.
log
(
beforeNumArr
,
afterNumArr
)
const
arr
=
[]
const
scrollBox
=
document
.
getElementsByClassName
(
'scroll-box'
)
const
scrollBox
=
document
.
getElementsByClassName
(
'scroll-box'
)
for
(
let
i
=
0
;
i
<
scrollBox
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
scrollBox
.
length
;
i
++
)
{
const
scrollBoxNode
=
scrollBox
[
i
]
const
scrollNode
=
scrollBox
[
i
]
const
scrollNum
=
scrollBoxNode
.
childNodes
const
beforeNum
=
beforeNumArr
[
i
]
addDigitAnimate
(
scrollNum
,
beforeNumArr
[
i
],
afterNumArr
[
i
])
const
afterNum
=
afterNumArr
[
i
]
}
const
isUp
=
afterNum
-
beforeNum
>=
0
}
// 创建单个数字动画
const
beforeChildNumArr
=
beforeNum
.
split
(
''
)
function
addDigitAnimate
(
scrollNum
,
beforeNumArr
,
afterNumArr
)
{
const
afterChildNumArr
=
afterNum
.
split
(
''
)
let
delay
=
0
let
delay
=
0
for
(
let
i
=
scrollNum
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
scrollNum
=
scrollNode
.
childNodes
const
scrollNumNode
=
scrollNum
[
i
]
for
(
let
j
=
beforeChildNumArr
.
length
-
1
;
j
>=
0
;
j
--
)
{
scrollNumNode
.
style
.
setProperty
(
'--i'
,
beforeNumArr
[
i
])
const
num
=
beforeChildNumArr
[
j
]
scrollNumNode
.
style
.
setProperty
(
'--j'
,
afterNumArr
[
i
])
const
num2
=
afterChildNumArr
[
j
]
const
beforePercent
=
isUp
?
num
*
-
5
:
-
50
-
num
*
5
const
d
=
Math
.
abs
(
beforeNumArr
[
i
]
-
afterNumArr
[
i
])
*
0.3
let
afterPercent
scrollNumNode
.
style
.
setProperty
(
'--duration'
,
d
)
let
duration
=
0
scrollNumNode
.
style
.
setProperty
(
'--delay'
,
delay
)
delay
+=
d
*
0.9
const
ulNode
=
scrollNum
[
j
].
childNodes
[
0
]
ulNode
.
setAttribute
(
const
ulNode
=
scrollNumNode
.
childNodes
[
0
]
'style'
,
ulNode
.
classList
.
remove
(
'animate'
)
'transform: translateY('
+
beforePercent
+
'%)'
ulNode
.
setAttribute
(
)
'style'
,
if
(
isUp
)
{
'transform: translateY('
+
beforeNumArr
[
i
]
*
-
9.09
+
'%)'
if
(
num2
>
num
)
{
)
afterPercent
=
num2
*
-
5
duration
=
num2
-
num
}
else
{
afterPercent
=
num2
*
-
5
-
50
duration
=
10
-
(
num
-
num2
)
}
}
else
{
if
(
num2
<
num
)
{
afterPercent
=
beforePercent
+
(
num
-
num2
)
*
5
duration
=
num
-
num2
}
else
{
afterPercent
=
num2
*
-
5
duration
=
10
-
(
num2
-
num
)
}
}
duration
=
duration
*
500
setTimeout
(()
=>
{
arr
.
push
({
ulNode
.
classList
.
add
(
'animate'
)
beforePercent
,
},
0
)
afterPercent
,
duration
,
if
(
isSafari
||
isWeChat
)
{
delay
,
let
timer
=
setTimeout
(()
=>
{
ulNode
:
scrollNum
[
j
].
childNodes
[
0
],
ulNode
.
setAttribute
(
})
'style'
,
delay
=
delay
+
duration
*
0.5
'animation: none;transform: translateY('
+
afterNumArr
[
i
]
*
-
9.09
+
'%)'
)
timer
=
null
},
delay
*
1000
)
}
}
}
}
arr
.
forEach
((
sObject
)
=>
{
const
{
beforePercent
,
afterPercent
,
duration
,
delay
,
ulNode
}
=
sObject
new
TWEEN
.
Tween
({
y
:
beforePercent
})
.
to
({
y
:
afterPercent
},
duration
)
.
delay
(
delay
)
.
easing
(
TWEEN
.
Easing
.
Quintic
.
Out
)
.
onUpdate
((
object
)
=>
{
ulNode
.
setAttribute
(
'style'
,
'transform: translateY('
+
object
.
y
+
'%)'
)
})
.
start
()
})
animate
()
}
}
function
createRandom
()
{
function
createRandom
()
{
...
@@ -322,6 +352,12 @@ function createRandom() {
...
@@ -322,6 +352,12 @@ function createRandom() {
return
arr
return
arr
}
}
function
animate
(
time
)
{
let
id
=
requestAnimationFrame
(
animate
)
var
result
=
TWEEN
.
update
(
time
)
if
(
!
result
)
cancelAnimationFrame
(
id
)
}
window
.
onload
=
()
=>
{
window
.
onload
=
()
=>
{
// echart渲染
// echart渲染
const
lineChart1
=
echarts
.
init
(
document
.
getElementById
(
'line_chart_1'
))
const
lineChart1
=
echarts
.
init
(
document
.
getElementById
(
'line_chart_1'
))
...
@@ -446,9 +482,9 @@ window.onload = () => {
...
@@ -446,9 +482,9 @@ window.onload = () => {
let
afterNumArr
=
[
'35345'
,
'83460'
,
'36765'
,
'36465'
]
let
afterNumArr
=
[
'35345'
,
'83460'
,
'36765'
,
'36465'
]
// 初始化
// 初始化
createMultiSrollNum
(
beforeNumArr
,
width
,
height
)
createMultiSrollNum
(
beforeNumArr
)
//
开始
动画
//
添加
动画
addMultiDigitAnimate
(
beforeNumArr
,
afterNumArr
)
addMultiDigitAnimate
(
beforeNumArr
,
afterNumArr
)
// 测试,点击第一列数字
// 测试,点击第一列数字
...
...
src/js/tween.umd.js
0 → 100644
View file @
f553889c
This diff is collapsed.
Click to expand it.
src/less/stat-bar.less
View file @
f553889c
...
@@ -36,9 +36,9 @@
...
@@ -36,9 +36,9 @@
margin-left: 10px;
margin-left: 10px;
}
}
.scroll-num {
.scroll-num {
width:
var(--width, 39px)
;
width:
39px
;
height:
var(--height, 50px)
;
height:
50px
;
line-height:
var(--height, 50px)
;
line-height:
50px
;
text-align: center;
text-align: center;
font-size: 41px;
font-size: 41px;
color: #01fff6;
color: #01fff6;
...
@@ -55,73 +55,5 @@
...
@@ -55,73 +55,5 @@
font-family: 'Source Han Sans CN';
font-family: 'Source Han Sans CN';
}
}
}
}
// .border-animate {
// animation: enhance-bounce-in-down 1s calc(var(--delay) * 1s) forwards;
// }
.animate {
animation: move calc(var(--duration) * 1s) calc(var(--delay) * 1s) linear,
bounce-in-down 1s calc((var(--duration) + var(--delay)) * 1s) forwards;
}
.init {
transform: translateY(calc(var(--i) * -9.09%));
}
}
@keyframes move {
from {
transform: translateY(calc(var(--i) * -9.09%));
filter: url(#blur);
}
to {
transform: translateY(calc(var(--j) * -9.09%));
filter: url(#blur);
}
}
@keyframes bounce-in-down {
from {
transform: translateY(calc(var(--j) * -9.09% - 1.0%));
filter: none;
}
25% {
transform: translateY(calc(var(--j) * -9.09% + 0.8%));
}
50% {
transform: translateY(calc(var(--j) * -9.09% - 1%));
}
70% {
transform: translateY(calc(var(--j) * -9.09% + 0.6%));
}
85% {
transform: translateY(calc(var(--j) * -9.09% - 0.3%));
}
to {
transform: translateY(calc(var(--j) * -9.09%));
}
}
}
// @keyframes enhance-bounce-in-down {
// 25% {
// transform: translateY(8%);
// }
// 50% {
// transform: translateY(-4%);
// }
// 70% {
// transform: translateY(2%);
// }
// 85% {
// transform: translateY(-1%);
// }
// to {
// transform: translateY(0);
// }
// }
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