Fix Affix flickering when scrolling

This commit is contained in:
ztplz 2019-01-03 00:53:40 +08:00 committed by 偏右
parent 429be2f87e
commit a019c0033f

View File

@ -97,6 +97,7 @@ export default class Affix extends React.Component<AffixProps, AffixState> {
if (shallowequal(affixStyle, originalAffixStyle)) {
return;
}
this.setState({ affixStyle: affixStyle as React.CSSProperties }, () => {
const affixed = !!this.state.affixStyle;
if ((affixStyle && !originalAffixStyle) || (!affixStyle && originalAffixStyle)) {
@ -162,7 +163,8 @@ export default class Affix extends React.Component<AffixProps, AffixState> {
const targetRect = getTargetRect(targetNode);
const targetInnerHeight =
(targetNode as Window).innerHeight || (targetNode as HTMLElement).clientHeight;
if (scrollTop > elemOffset.top - (offsetTop as number) && offsetMode.top) {
// ref: https://github.com/ant-design/ant-design/issues/13662
if (scrollTop > elemOffset.top - (offsetTop as number) - 1 && offsetMode.top) {
// Fixed Top
const width = elemOffset.width;
const top = targetRect.top + (offsetTop as number);