File tree Expand file tree Collapse file tree 4 files changed +16
-11
lines changed
Expand file tree Collapse file tree 4 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -65,18 +65,18 @@ const NoticeBarDemo = () => {
6565
6666 < h2 > { translated . scrollable } </ h2 >
6767 < NoticeBar content = { translated . textShort } scrollable />
68- < br />
68+ < br style = { { display : 'block' , height : '10px' } } />
6969 < NoticeBar content = { translated . text } scrollable = { false } />
7070
7171 < h2 > { translated . mode } </ h2 >
7272 < NoticeBar closeable onClick = { hello } >
7373 { translated . text }
7474 </ NoticeBar >
75- < br />
75+ < br style = { { display : 'block' , height : '10px' } } />
7676 < NoticeBar closeable rightIcon = { < CircleClose /> } onClick = { hello } >
7777 { translated . text }
7878 </ NoticeBar >
79- < br />
79+ < br style = { { display : 'block' , height : '10px' } } />
8080 < NoticeBar
8181 leftIcon = {
8282 < img
Original file line number Diff line number Diff line change 3232 }
3333
3434 .left-icon {
35+ display : flex ;
3536 height : $noticebar-left-icon-width ;
3637 min-width : $noticebar-left-icon-width ;
3738 margin : $noticebar-lefticon-margin ;
Original file line number Diff line number Diff line change @@ -119,7 +119,9 @@ export const NoticeBar: FunctionComponent<
119119 childCount,
120120 }
121121 } , [ children ] )
122+ // 滚动消息的总高度
122123 let trackSize = childCount * Number ( height )
124+ // 设置最小偏移量(最后一条的偏移位置)
123125 const minOffset = ( ( ) => {
124126 if ( rect ) {
125127 const base = isVertical ? rect . height : rect . width
@@ -134,9 +136,7 @@ export const NoticeBar: FunctionComponent<
134136 scrollList . current = [ ] . concat ( childs )
135137 } else {
136138 scrollList . current = [ ] . concat ( list )
137- setTimeout ( ( ) => {
138- startRollEasy ( )
139- } , Number ( duration ) )
139+ startRollEasy ( )
140140 }
141141 } else {
142142 initScrollWrap ( content )
@@ -297,11 +297,9 @@ export const NoticeBar: FunctionComponent<
297297
298298 useEffect ( ( ) => {
299299 if ( isVertical && children ) {
300- setTimeout ( ( ) => {
301- init ( )
302- stopAutoPlay ( )
303- autoplay ( )
304- } , 300 )
300+ init ( )
301+ stopAutoPlay ( )
302+ autoplay ( )
305303 }
306304 } , [ children , container ?. current ] )
307305
@@ -366,6 +364,9 @@ export const NoticeBar: FunctionComponent<
366364
367365 const getStyle = ( moveOffset = offset ) => {
368366 const target = innerRef . current
367+ if ( ! target ) {
368+ return
369+ }
369370 let _offset = 0
370371 // 容器高度-元素高度
371372 const val = ( rect ?. height || 0 ) - height
Original file line number Diff line number Diff line change @@ -360,6 +360,9 @@ export const NoticeBar: FunctionComponent<
360360
361361 const getStyle = ( moveOffset = offset ) => {
362362 const target = innerRef . current
363+ if ( ! target ) {
364+ return
365+ }
363366 let _offset = 0
364367 // 容器高度-元素高度
365368 const val = rect . height - height
You can’t perform that action at this time.
0 commit comments