Support viewport resizing (#16)
This commit is contained in:
38
src/utils.js
38
src/utils.js
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user