Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
mini-program
/
points-mall
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit dae797da
authored
Sep 10, 2025
by
zhangxw
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
首页公告动画优化
1 parent
1db565e0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
14 deletions
pages/tab/index/index.js
pages/tab/index/index.wxml
pages/tab/index/index.js
View file @
dae797d
...
...
@@ -39,32 +39,35 @@ Page({
navbarReady
()
{
wx
.
nextTick
(()
=>
{
this
.
clearAnimationTimer
()
this
.
startAnimation
()
})
},
// 顶部公告动画
startAnimation
:
function
()
{
const
query
=
wx
.
createSelectorQuery
()
query
.
select
(
'.text-container'
).
boundingClientRect
()
query
.
select
(
'.text'
).
boundingClientRect
()
query
.
exec
((
res
)
=>
{
const
containerWidth
=
res
[
0
]?.
width
const
textWidth
=
res
[
1
]?
.
width
// 只有文字宽度超过容器宽度时才滚动
if
(
!
res
[
0
]
||
!
res
[
1
])
return
const
containerWidth
=
res
[
0
]
.
width
const
textWidth
=
res
[
1
].
width
if
(
textWidth
>
containerWidth
)
{
const
animation
=
wx
.
createAnimation
({
duration
:
(
textWidth
/
30
)
*
1000
,
// 根据文字长度调整滚动时间
duration
:
(
textWidth
/
30
)
*
1000
,
timingFunction
:
'linear'
,
delay
:
0
})
animation
.
translateX
(
-
textWidth
).
step
()
this
.
setData
({
animationData
:
animation
.
export
()
animationData
:
animation
.
export
(),
shouldAnimate
:
true
})
//
设置循环
setTimeout
(()
=>
{
this
.
resetAnimation
()
;
//
使用箭头函数保持this指向
this
.
animationTimer
=
setTimeout
(()
=>
{
this
.
resetAnimation
()
},
(
textWidth
/
30
)
*
1000
)
}
else
{
this
.
setData
({
shouldAnimate
:
false
})
}
})
},
...
...
@@ -79,9 +82,35 @@ Page({
this
.
setData
({
animationData
:
animation
.
export
()
})
setTimeout
(()
=>
{
this
.
animationTimer
=
setTimeout
(()
=>
{
this
.
startAnimation
()
},
50
)
},
300
)
// 增加延迟,让用户能看到起始位置
},
// 清理和恢复方法
clearAnimationTimer
()
{
if
(
this
.
animationTimer
)
{
clearTimeout
(
this
.
animationTimer
)
this
.
animationTimer
=
null
}
},
restoreAnimation
()
{
if
(
this
.
data
.
shouldAnimate
)
{
this
.
clearAnimationTimer
()
// 重新初始化动画
const
animation
=
wx
.
createAnimation
({
duration
:
0
,
timingFunction
:
'linear'
})
animation
.
translateX
(
0
).
step
()
this
.
setData
({
animationData
:
animation
.
export
()
})
// 短暂延迟后重新开始动画
setTimeout
(()
=>
{
this
.
startAnimation
()
},
50
)
}
},
/**
...
...
@@ -329,17 +358,24 @@ Page({
this
.
getGoodsList
()
this
.
getCategory
()
this
.
getHomeData
()
if
(
this
.
data
.
shouldAnimate
)
{
// 恢复公告动画
this
.
resetAnimation
()
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide
:
function
()
{},
onHide
:
function
()
{
this
.
clearAnimationTimer
()
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload
:
function
()
{},
onUnload
:
function
()
{
this
.
clearAnimationTimer
()
},
refreshPage
()
{
this
.
setData
({
...
...
pages/tab/index/index.wxml
View file @
dae797d
...
...
@@ -26,7 +26,7 @@
<!-- 公告 -->
<view class="notic-box">
<view class="text-container">
<view class="text" animation="{{
animationData
}}">郑重提醒:根据国家税务总局2025第16号公告,提现收入也将纳入个人累计收入计算税额,以上政策将于 10 月 1 日正式实施。</view>
<view class="text" animation="{{
shouldAnimate ? animationData : ''
}}">郑重提醒:根据国家税务总局2025第16号公告,提现收入也将纳入个人累计收入计算税额,以上政策将于 10 月 1 日正式实施。</view>
</view>
<view class="detail-btn" bindtap="policyDetail">
<text>详情</text>
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment