flamingo-ui
Version:
火烈鸟UI组件库
30 lines (29 loc) • 844 B
JavaScript
function getPixelRatio(context) {
var backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}
function debounce(func, wait = 500, immediate = true) {
let timer;
return function() {
let context = this;
let args = arguments;
if (timer)
clearTimeout(timer);
if (immediate) {
var callNow = !timer;
timer = setTimeout(() => {
timer = null;
}, wait);
if (callNow)
func.apply(context, args);
} else {
timer = setTimeout(function() {
func.apply(context, args);
}, wait);
}
};
}
export {
debounce,
getPixelRatio
};