mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 07:56:28 +08:00
fix: should test if window exist, close: #3216
This commit is contained in:
parent
1e65cac784
commit
9685d06f45
17
components/_util/getScroll.tsx
Normal file
17
components/_util/getScroll.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export default function getScroll(target, top) {
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const prop = top ? 'pageYOffset' : 'pageXOffset';
|
||||||
|
const method = top ? 'scrollTop' : 'scrollLeft';
|
||||||
|
const isWindow = target === window;
|
||||||
|
|
||||||
|
let ret = isWindow ? target[prop] : target[method];
|
||||||
|
// ie6,7,8 standard mode
|
||||||
|
if (isWindow && typeof ret !== 'number') {
|
||||||
|
ret = window.document.documentElement[method];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
@ -4,20 +4,7 @@ import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import shallowequal from 'shallowequal';
|
import shallowequal from 'shallowequal';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
|
import getScroll from '../_util/getScroll';
|
||||||
function getScroll(target, top) {
|
|
||||||
const prop = top ? 'pageYOffset' : 'pageXOffset';
|
|
||||||
const method = top ? 'scrollTop' : 'scrollLeft';
|
|
||||||
const isWindow = target === window;
|
|
||||||
|
|
||||||
let ret = isWindow ? target[prop] : target[method];
|
|
||||||
// ie6,7,8 standard mode
|
|
||||||
if (isWindow && typeof ret !== 'number') {
|
|
||||||
ret = window.document.documentElement[method];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTargetRect(target): any {
|
function getTargetRect(target): any {
|
||||||
return target !== window ?
|
return target !== window ?
|
||||||
|
@ -4,6 +4,7 @@ import Icon from '../icon';
|
|||||||
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
|
import getScroll from '../_util/getScroll';
|
||||||
|
|
||||||
const reqAnimFrame = (() => {
|
const reqAnimFrame = (() => {
|
||||||
if (window.requestAnimationFrame) {
|
if (window.requestAnimationFrame) {
|
||||||
@ -29,24 +30,6 @@ const easeInOutCubic = (t, b, c, d) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function getScroll(target, top) {
|
|
||||||
if (typeof window === 'undefined') {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const prop = top ? 'pageYOffset' : 'pageXOffset';
|
|
||||||
const method = top ? 'scrollTop' : 'scrollLeft';
|
|
||||||
const isWindow = target === window;
|
|
||||||
|
|
||||||
let ret = isWindow ? target[prop] : target[method];
|
|
||||||
// ie6,7,8 standard mode
|
|
||||||
if (isWindow && typeof ret !== 'number') {
|
|
||||||
ret = window.document.documentElement[method];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BackTopProps {
|
export interface BackTopProps {
|
||||||
visibilityHeight?: number;
|
visibilityHeight?: number;
|
||||||
onClick?: (event) => void;
|
onClick?: (event) => void;
|
||||||
|
Loading…
Reference in New Issue
Block a user