Skip to content

Commit c16cdc9

Browse files
committed
Merge pull request marcj#65 from dustyholmes-wf/reset-scrollers
Fix issue caused by not resetting both scrollbar positions
2 parents 921e954 + 4086a90 commit c16cdc9

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/ResizeSensor.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,17 @@
8686
var shrink = element.resizeSensor.childNodes[1];
8787
var shrinkChild = shrink.childNodes[0];
8888

89-
var lastShrinkWidth, lastShrinkHeight;
90-
var lastExpandWidth, lastExpandHeight;
89+
var lastWidth, lastHeight;
9190

9291
var reset = function() {
93-
resetExpand();
94-
resetShrink();
95-
};
96-
97-
var resetExpand = function() {
9892
expandChild.style.width = expand.offsetWidth + 10 + 'px';
9993
expandChild.style.height = expand.offsetHeight + 10 + 'px';
10094
expand.scrollLeft = expand.scrollWidth;
10195
expand.scrollTop = expand.scrollHeight;
102-
lastExpandWidth = element.offsetWidth;
103-
lastExpandHeight = element.offsetHeight;
104-
};
105-
106-
var resetShrink = function() {
10796
shrink.scrollLeft = shrink.scrollWidth;
10897
shrink.scrollTop = shrink.scrollHeight;
109-
lastShrinkWidth = element.offsetWidth;
110-
lastShrinkHeight = element.offsetHeight;
98+
lastWidth = element.offsetWidth;
99+
lastHeight = element.offsetHeight;
111100
};
112101

113102
reset();
@@ -125,20 +114,16 @@
125114
el.addEventListener(name, cb);
126115
}
127116
};
117+
118+
var onScroll = function() {
119+
if (element.offsetWidth != lastWidth || element.offsetHeight != lastHeight) {
120+
changed();
121+
}
122+
reset();
123+
}
128124

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);
142127
}
143128

144129
if ("[object Array]" === Object.prototype.toString.call(element)

0 commit comments

Comments
 (0)