Skip to content

Commit 660e26e

Browse files
authored
fix: divisor cannot be 0 (#72)
* Divisor cannot be 0 * fix another * some test case * update
1 parent ba168ae commit 660e26e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ScrollBar.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar
126126
const enableScrollRange = this.getEnableScrollRange();
127127
const enableHeightRange = this.getEnableHeightRange();
128128

129-
const ptg = newTop / enableHeightRange;
129+
const ptg = enableHeightRange ? newTop / enableHeightRange : 0;
130130
const newScrollTop = Math.ceil(ptg * enableScrollRange);
131131
this.moveRaf = raf(() => {
132132
onScroll(newScrollTop);
@@ -153,19 +153,22 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar
153153

154154
getEnableScrollRange = () => {
155155
const { scrollHeight, height } = this.props;
156-
return scrollHeight - height;
156+
return scrollHeight - height || 0;
157157
};
158158

159159
getEnableHeightRange = () => {
160160
const { height } = this.props;
161161
const spinHeight = this.getSpinHeight();
162-
return height - spinHeight;
162+
return height - spinHeight || 0;
163163
};
164164

165165
getTop = () => {
166166
const { scrollTop } = this.props;
167167
const enableScrollRange = this.getEnableScrollRange();
168168
const enableHeightRange = this.getEnableHeightRange();
169+
if (scrollTop === 0 || enableScrollRange === 0) {
170+
return 0;
171+
}
169172
const ptg = scrollTop / enableScrollRange;
170173
return ptg * enableHeightRange;
171174
};

0 commit comments

Comments
 (0)