@@ -67,7 +67,7 @@ VantComponent({
67
67
getRect ( this , '.van-notice-bar__wrap' ) ,
68
68
] ) . then ( ( rects ) => {
69
69
const [ contentRect , wrapRect ] = rects ;
70
- const { speed , scrollable, delay } = this . data ;
70
+ const { scrollable } = this . data ;
71
71
if (
72
72
contentRect == null ||
73
73
wrapRect == null ||
@@ -79,24 +79,32 @@ VantComponent({
79
79
}
80
80
81
81
if ( scrollable || wrapRect . width < contentRect . width ) {
82
- const duration =
83
- ( ( wrapRect . width + contentRect . width ) / speed ) * 1000 ;
84
-
85
- this . wrapWidth = wrapRect . width ;
86
- this . contentWidth = contentRect . width ;
87
- this . duration = duration ;
88
- this . animation = wx . createAnimation ( {
89
- duration,
90
- timingFunction : 'linear' ,
91
- delay,
92
- } ) ;
82
+ this . initAnimation ( wrapRect . width , contentRect . width ) ;
93
83
94
84
this . scroll ( true ) ;
95
85
}
96
86
} ) ;
97
87
} ) ;
98
88
} ,
99
89
90
+ initAnimation ( warpWidth : number , contentWidth : number ) {
91
+ const { speed, delay } = this . data ;
92
+
93
+ this . wrapWidth = warpWidth ;
94
+ this . contentWidth = contentWidth ;
95
+
96
+ // begin 0
97
+ this . contentDuration = ( contentWidth / speed ) * 1000 ;
98
+ // begin -wrapWidth
99
+ this . duration = ( ( warpWidth + contentWidth ) / speed ) * 1000 ;
100
+
101
+ this . animation = wx . createAnimation ( {
102
+ duration : this . contentDuration ,
103
+ timingFunction : 'linear' ,
104
+ delay,
105
+ } ) ;
106
+ } ,
107
+
100
108
scroll ( isInit = false ) {
101
109
this . timer && clearTimeout ( this . timer ) ;
102
110
this . timer = null ;
@@ -108,18 +116,20 @@ VantComponent({
108
116
. export ( ) ,
109
117
} ) ;
110
118
119
+ const duration = isInit ? this . contentDuration : this . duration ;
120
+
111
121
requestAnimationFrame ( ( ) => {
112
122
this . setData ( {
113
123
animationData : this . animation
114
124
. translateX ( - this . contentWidth )
115
- . step ( )
125
+ . step ( { duration } )
116
126
. export ( ) ,
117
127
} ) ;
118
128
} ) ;
119
129
120
130
this . timer = setTimeout ( ( ) => {
121
131
this . scroll ( ) ;
122
- } , this . duration + this . data . delay ) ;
132
+ } , duration + this . data . delay ) ;
123
133
} ,
124
134
125
135
onClickIcon ( event ) {
0 commit comments