|
143 | 143 | var expand = element.resizeSensor.childNodes[0];
|
144 | 144 | var expandChild = expand.childNodes[0];
|
145 | 145 | var shrink = element.resizeSensor.childNodes[1];
|
| 146 | + var dirty, rafId, newWidth, newHeight; |
| 147 | + var lastWidth = element.offsetWidth; |
| 148 | + var lastHeight = element.offsetHeight; |
146 | 149 |
|
147 | 150 | var reset = function() {
|
148 |
| - expandChild.style.width = 100000 + 'px'; |
149 |
| - expandChild.style.height = 100000 + 'px'; |
| 151 | + expandChild.style.width = '100000px'; |
| 152 | + expandChild.style.height = '100000px'; |
150 | 153 |
|
151 | 154 | expand.scrollLeft = 100000;
|
152 | 155 | expand.scrollTop = 100000;
|
|
156 | 159 | };
|
157 | 160 |
|
158 | 161 | reset();
|
159 |
| - var dirty = false; |
160 | 162 |
|
161 |
| - var dirtyChecking = function() { |
162 |
| - if (!element.resizedAttached) return; |
| 163 | + var onResized = function() { |
| 164 | + rafId = 0; |
163 | 165 |
|
164 |
| - if (dirty) { |
| 166 | + if (!dirty) return; |
| 167 | + |
| 168 | + lastWidth = newWidth; |
| 169 | + lastHeight = newHeight; |
| 170 | + |
| 171 | + if (element.resizedAttached) { |
165 | 172 | element.resizedAttached.call();
|
166 |
| - dirty = false; |
167 | 173 | }
|
168 |
| - |
169 |
| - requestAnimationFrame(dirtyChecking); |
170 | 174 | };
|
171 | 175 |
|
172 |
| - requestAnimationFrame(dirtyChecking); |
173 |
| - var lastWidth, lastHeight; |
174 |
| - var cachedWidth, cachedHeight; //useful to not query offsetWidth twice |
175 |
| - |
176 | 176 | var onScroll = function() {
|
177 |
| - if ((cachedWidth = element.offsetWidth) != lastWidth || (cachedHeight = element.offsetHeight) != lastHeight) { |
178 |
| - dirty = true; |
| 177 | + newWidth = element.offsetWidth; |
| 178 | + newHeight = element.offsetHeight; |
| 179 | + dirty = newWidth != lastWidth || newHeight != lastHeight; |
| 180 | + |
| 181 | + if (dirty && !rafId) { |
| 182 | + rafId = requestAnimationFrame(onResized); |
| 183 | + } |
179 | 184 |
|
180 |
| - lastWidth = cachedWidth; |
181 |
| - lastHeight = cachedHeight; |
182 |
| - } |
183 |
| - reset(); |
| 185 | + reset(); |
184 | 186 | };
|
185 | 187 |
|
186 | 188 | var addEvent = function(el, name, cb) {
|
|
0 commit comments