Support viewport resizing (#16)

This commit is contained in:
gavin
2018-08-30 01:02:58 +00:00
committed by Gitea
parent a2d7402cfa
commit 2c83c47afc
4 changed files with 137 additions and 73 deletions

View File

@@ -9,25 +9,25 @@ export const sqrt2 = Math.sqrt(2);
// (2*S gives long width)
export const sqrt3 = Math.sqrt(3);
export function throttleEvent(type, name, obj) {
obj = obj || window;
let running = false;
let throttle = () => {
if (!running) {
running = true;
requestAnimationFrame(() => {
obj.dispatchEvent(new CustomEvent(name));
running = false;
});
}
}
obj.addEventListener(type, throttle);
}
throttleEvent('resize', 'optimizedResize');
//export function throttleEvent(type, name, obj) {
// obj = obj || window;
// let running = false;
//
// let throttle = () => {
// if (!running) {
// running = true;
//
// requestAnimationFrame(() => {
// obj.dispatchEvent(new CustomEvent(name));
// running = false;
// });
// }
// }
//
// obj.addEventListener(type, throttle);
//}
//
//throttleEvent('resize', 'optimizedResize');
export function clone(obj) {
return JSON.parse(JSON.stringify(obj));