@@ -4,9 +4,13 @@ import { BAR_MAP, renderThumbStyle} from './util';
4
4
import { on , off } from '../../libs/utils/dom' ;
5
5
6
6
export class Bar extends Component {
7
-
8
7
constructor ( props ) {
9
8
super ( props ) ;
9
+
10
+ this . clickTrackHandler = this . clickTrackHandler . bind ( this ) ;
11
+ this . clickThumbHandler = this . clickThumbHandler . bind ( this ) ;
12
+ this . mouseMoveDocumentHandler = this . mouseMoveDocumentHandler . bind ( this ) ;
13
+ this . mouseUpDocumentHandler = this . mouseUpDocumentHandler . bind ( this ) ;
10
14
}
11
15
12
16
get bar ( ) {
@@ -24,14 +28,14 @@ export class Bar extends Component {
24
28
25
29
clickTrackHandler ( e ) {
26
30
const offset = Math . abs ( e . target . getBoundingClientRect ( ) [ this . bar . direction ] - e [ this . bar . client ] ) ;
27
- const thumbHalf = ( this . refs . thumb [ this . bar . offset ] / 2 ) ;
28
- const thumbPositionPercentage = ( ( offset - thumbHalf ) * 100 / this . root [ this . bar . offset ] ) ;
31
+ const thumbHalf = ( this . thumbRef [ this . bar . offset ] / 2 ) ;
32
+ const thumbPositionPercentage = ( ( offset - thumbHalf ) * 100 / this . rootRef [ this . bar . offset ] ) ;
29
33
30
34
this . wrap [ this . bar . scroll ] = ( thumbPositionPercentage * this . wrap [ this . bar . scrollSize ] / 100 ) ;
31
35
}
32
36
33
37
startDrag ( e ) {
34
- e . stopImmediatePropagation ( ) ;
38
+ e . nativeEvent . stopImmediatePropagation ;
35
39
this . cursorDown = true ;
36
40
37
41
on ( document , 'mousemove' , this . mouseMoveDocumentHandler ) ;
@@ -45,9 +49,9 @@ export class Bar extends Component {
45
49
46
50
if ( ! prevPage ) return ;
47
51
48
- const offset = ( e [ this . bar . client ] - this . root . getBoundingClientRect ( ) [ this . bar . direction ] ) ;
49
- const thumbClickPosition = ( this . refs . thumb [ this . bar . offset ] - prevPage ) ;
50
- const thumbPositionPercentage = ( ( offset - thumbClickPosition ) * 100 / this . root [ this . bar . offset ] ) ;
52
+ const offset = ( e [ this . bar . client ] - this . rootRef . getBoundingClientRect ( ) [ this . bar . direction ] ) ;
53
+ const thumbClickPosition = ( this . thumbRef [ this . bar . offset ] - prevPage ) ;
54
+ const thumbPositionPercentage = ( ( offset - thumbClickPosition ) * 100 / this . rootRef [ this . bar . offset ] ) ;
51
55
52
56
this . wrap [ this . bar . scroll ] = ( thumbPositionPercentage * this . wrap [ this . bar . scrollSize ] / 100 ) ;
53
57
}
@@ -64,13 +68,13 @@ export class Bar extends Component {
64
68
65
69
return (
66
70
< div
67
- ref = " root"
71
+ ref = { root => this . rootRef = root }
68
72
className = { this . classNames ( 'el-scrollbar__bar' , `is-${ this . bar . key } ` ) }
69
- onMouseDown = { this . clickTrackHandler . bind ( this ) } >
73
+ onMouseDown = { this . clickTrackHandler } >
70
74
< div
71
- ref = " thumb"
75
+ ref = { thumb => this . thumbRef = thumb }
72
76
className = "el-scrollbar__thumb"
73
- onMouseDown = { this . clickThumbHandler . bind ( this ) }
77
+ onMouseDown = { this . clickThumbHandler }
74
78
style = { renderThumbStyle ( { size, move, bar : this . bar } ) } >
75
79
</ div >
76
80
</ div >
@@ -83,5 +87,4 @@ Bar.propTypes = {
83
87
size : PropTypes . string ,
84
88
move : PropTypes . number ,
85
89
getParentWrap : PropTypes . func . isRequired
86
-
87
90
}
0 commit comments