You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
829 B
37 lines
829 B
4 years ago
|
/* eslint-disable import/prefer-default-export */
|
||
|
export const throttle = (fn, delay) => {
|
||
|
let timer = null;
|
||
|
return function(...args) {
|
||
|
const context = this;
|
||
|
clearTimeout(timer);
|
||
|
timer = setTimeout(() => {
|
||
|
fn.apply(context, args);
|
||
|
}, delay);
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export const getScrollTop = () => {
|
||
|
let scrollTop = 0;
|
||
|
if (document.documentElement && document.documentElement.scrollTop) {
|
||
|
scrollTop = document.documentElement.scrollTop;
|
||
|
} else if (document.body) {
|
||
|
scrollTop = document.body.scrollTop;
|
||
|
}
|
||
|
return scrollTop;
|
||
|
};
|
||
|
|
||
|
export const getLink = (link) => {
|
||
|
if (`${link}`.length > 1 && /^\/[^/]/.test(`${link}`)) {
|
||
|
return `${window.rootPath}${link}`;
|
||
|
}
|
||
|
return link;
|
||
|
};
|
||
|
|
||
|
export const parseJSONStr = (str) => {
|
||
|
try {
|
||
|
return JSON.parse(str);
|
||
|
} catch (err) {
|
||
|
return str;
|
||
|
}
|
||
|
}
|