|
86 | 86 | var shrink = element.resizeSensor.childNodes[1]; |
87 | 87 | var shrinkChild = shrink.childNodes[0]; |
88 | 88 |
|
89 | | - var lastShrinkWidth, lastShrinkHeight; |
90 | | - var lastExpandWidth, lastExpandHeight; |
| 89 | + var lastWidth, lastHeight; |
91 | 90 |
|
92 | 91 | var reset = function() { |
93 | | - resetExpand(); |
94 | | - resetShrink(); |
95 | | - }; |
96 | | - |
97 | | - var resetExpand = function() { |
98 | 92 | expandChild.style.width = expand.offsetWidth + 10 + 'px'; |
99 | 93 | expandChild.style.height = expand.offsetHeight + 10 + 'px'; |
100 | 94 | expand.scrollLeft = expand.scrollWidth; |
101 | 95 | expand.scrollTop = expand.scrollHeight; |
102 | | - lastExpandWidth = element.offsetWidth; |
103 | | - lastExpandHeight = element.offsetHeight; |
104 | | - }; |
105 | | - |
106 | | - var resetShrink = function() { |
107 | 96 | shrink.scrollLeft = shrink.scrollWidth; |
108 | 97 | shrink.scrollTop = shrink.scrollHeight; |
109 | | - lastShrinkWidth = element.offsetWidth; |
110 | | - lastShrinkHeight = element.offsetHeight; |
| 98 | + lastWidth = element.offsetWidth; |
| 99 | + lastHeight = element.offsetHeight; |
111 | 100 | }; |
112 | 101 |
|
113 | 102 | reset(); |
|
125 | 114 | el.addEventListener(name, cb); |
126 | 115 | } |
127 | 116 | }; |
| 117 | + |
| 118 | + var onScroll = function() { |
| 119 | + if (element.offsetWidth != lastWidth || element.offsetHeight != lastHeight) { |
| 120 | + changed(); |
| 121 | + } |
| 122 | + reset(); |
| 123 | + } |
128 | 124 |
|
129 | | - addEvent(expand, 'scroll', function() { |
130 | | - if (element.offsetWidth > lastExpandWidth || element.offsetHeight > lastExpandHeight) { |
131 | | - changed(); |
132 | | - } |
133 | | - resetExpand(); |
134 | | - }); |
135 | | - |
136 | | - addEvent(shrink, 'scroll',function() { |
137 | | - if (element.offsetWidth < lastShrinkWidth || element.offsetHeight < lastShrinkHeight) { |
138 | | - changed(); |
139 | | - } |
140 | | - resetShrink(); |
141 | | - }); |
| 125 | + addEvent(expand, 'scroll', onScroll); |
| 126 | + addEvent(shrink, 'scroll', onScroll); |
142 | 127 | } |
143 | 128 |
|
144 | 129 | if ("[object Array]" === Object.prototype.toString.call(element) |
|
0 commit comments