@@ -60,11 +60,11 @@ class LazyLoadImage extends React.Component {
60
60
}
61
61
62
62
componentDidUpdate ( ) {
63
- if ( this . refs . placeholder ) {
63
+ if ( this . placeholder ) {
64
64
const boundingBox = {
65
- bottom : this . refs . placeholder . offsetTop +
66
- this . refs . placeholder . offsetHeight ,
67
- top : this . refs . placeholder . offsetTop
65
+ bottom : this . placeholder . offsetTop +
66
+ this . placeholder . offsetHeight ,
67
+ top : this . placeholder . offsetTop
68
68
} ;
69
69
70
70
if ( this . previousBoundingBox . bottom !== boundingBox . bottom ||
@@ -91,18 +91,18 @@ class LazyLoadImage extends React.Component {
91
91
}
92
92
93
93
isImageInViewport ( scrollPosition ) {
94
- if ( ! this . refs . placeholder ) {
94
+ if ( ! this . placeholder ) {
95
95
return false ;
96
96
}
97
97
98
98
const { threshold } = this . props ;
99
99
const boundingBox = {
100
- bottom : this . refs . placeholder . offsetTop +
101
- this . refs . placeholder . offsetHeight ,
102
- left : this . refs . placeholder . offsetLeft ,
103
- right : this . refs . placeholder . offsetLeft +
104
- this . refs . placeholder . offsetWidth ,
105
- top : this . refs . placeholder . offsetTop
100
+ bottom : this . placeholder . offsetTop +
101
+ this . placeholder . offsetHeight ,
102
+ left : this . placeholder . offsetLeft ,
103
+ right : this . placeholder . offsetLeft +
104
+ this . placeholder . offsetWidth ,
105
+ top : this . placeholder . offsetTop
106
106
} ;
107
107
const viewport = {
108
108
bottom : scrollPosition . y + window . innerHeight ,
@@ -123,12 +123,13 @@ class LazyLoadImage extends React.Component {
123
123
const { className, height, placeholder, width } = this . props ;
124
124
125
125
if ( placeholder ) {
126
- return React . cloneElement ( placeholder , { ref : 'placeholder' } ) ;
126
+ return React . cloneElement ( placeholder ,
127
+ { ref : el => this . placeholder = el } ) ;
127
128
}
128
129
129
130
return (
130
131
< span className = { 'lazy-load-image-placeholder ' + className }
131
- ref = " placeholder"
132
+ ref = { el => this . placeholder = el }
132
133
style = { { height, width } } >
133
134
</ span >
134
135
) ;
@@ -145,7 +146,7 @@ class LazyLoadImage extends React.Component {
145
146
return (
146
147
< img
147
148
{ ...props }
148
- ref = " image" />
149
+ ref = { img => this . image = img } />
149
150
) ;
150
151
}
151
152
}
0 commit comments