mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
* fix: Tabbar icon line-height * [new feature] progress add showPivot prop * [new feature] TabItem support vue-router * [new feature] update document header style * [Doc] add toast english ducoment * [bugfix] Search box-sizing wrong * [Doc] update vant-demo respo * [Doc] translate theme & demo pages * [Doc] add Internationalization document * [bugfix] remove unnecessary props * [fix] optimize clickoutside * [new feature] optimize find-parent * [new feature]: change document title accordinng to language * [new feature] Pagination code review * [improvement] adjust icon-font unicode * [improvement] Icon spinner color inherit * [improvement] icon default width * [bugfix] DateTimePicker validate date props * [bugfix] Tab item text ellipsis * [improvement] optimize single line ellipsis * [Improvement] optimzie staticClass * [Improvement] Button: use sfc instread of jsx * [Improvement] update actionsheet close icon style * fix: yarn.lock * fix: icon test cases * [bugfix] errors during ssr
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
import { isServer } from './index';
|
|
|
|
export default {
|
|
debounce(func, wait, immediate) {
|
|
let timeout, args, context, timestamp, result;
|
|
return function() {
|
|
context = this;
|
|
args = arguments;
|
|
timestamp = new Date();
|
|
const later = () => {
|
|
const last = (new Date()) - timestamp;
|
|
if (last < wait) {
|
|
timeout = setTimeout(later, wait - last);
|
|
} else {
|
|
timeout = null;
|
|
result = func.apply(context, args);
|
|
}
|
|
};
|
|
if (!timeout) {
|
|
timeout = setTimeout(later, wait);
|
|
}
|
|
return result;
|
|
};
|
|
},
|
|
|
|
// 找到最近的触发滚动事件的元素
|
|
getScrollEventTarget(element) {
|
|
let currentNode = element;
|
|
// bugfix, see http://w3help.org/zh-cn/causes/SD9013 and http://stackoverflow.com/questions/17016740/onscroll-function-is-not-working-for-chrome
|
|
while (currentNode && currentNode.tagName !== 'HTML' && currentNode.tagName !== 'BODY' && currentNode.nodeType === 1) {
|
|
const overflowY = this.getComputedStyle(currentNode).overflowY;
|
|
if (overflowY === 'scroll' || overflowY === 'auto') {
|
|
return currentNode;
|
|
}
|
|
currentNode = currentNode.parentNode;
|
|
}
|
|
return window;
|
|
},
|
|
|
|
// 判断元素是否被加入到页面节点内
|
|
isAttached(element) {
|
|
let currentNode = element.parentNode;
|
|
while (currentNode) {
|
|
if (currentNode.tagName === 'HTML') {
|
|
return true;
|
|
}
|
|
if (currentNode.nodeType === 11) {
|
|
return false;
|
|
}
|
|
currentNode = currentNode.parentNode;
|
|
}
|
|
return false;
|
|
},
|
|
|
|
// 获取滚动高度
|
|
getScrollTop(element) {
|
|
return 'scrollTop' in element ? element.scrollTop : element.pageYOffset;
|
|
},
|
|
|
|
// 设置滚动高度
|
|
setScrollTop(element, value) {
|
|
'scrollTop' in element ? element.scrollTop = value : element.scrollTo(element.scrollX, value);
|
|
},
|
|
|
|
// 获取元素距离顶部高度
|
|
getElementTop(element) {
|
|
return (element === window ? 0 : element.getBoundingClientRect().top) + this.getScrollTop(window);
|
|
},
|
|
|
|
getVisibleHeight(element) {
|
|
return element === window ? element.innerHeight : element.getBoundingClientRect().height;
|
|
},
|
|
|
|
getComputedStyle: !isServer && document.defaultView.getComputedStyle.bind(document.defaultView)
|
|
};
|