Stop canvases that are not in viewport

This commit is contained in:
wswidzinski 2018-01-17 23:50:09 +01:00
parent d5a93d0e95
commit 036eff54bf
1 changed files with 24 additions and 3 deletions

View File

@ -1,13 +1,29 @@
/* eslint-disable */
import inView from 'in-view';
class Canvas { class Canvas {
constructor() { constructor() {
this.connect = new CABLES.Patch({ this.initConnectCanvas();
this.initKleinCanvas();
}
initConnectCanvas() {
const connect = new CABLES.Patch({
patchFile: 'assets/connect.json', patchFile: 'assets/connect.json',
prefixAssetPath: '', prefixAssetPath: '',
glCanvasId: 'connect', glCanvasId: 'connect',
glCanvasResizeToWindow: true, glCanvasResizeToWindow: true,
silent: true silent: true,
}); });
connect.pause();
inView.offset(0);
inView('.team').on('enter', () => connect.resume());
inView('.team').on('exit', () => connect.pause());
}
initKleinCanvas() {
CABLES.EMBED.addPatch( CABLES.EMBED.addPatch(
'klein', 'klein',
{ {
@ -16,9 +32,14 @@ class Canvas {
silent: true silent: true
} }
) )
CABLES.patch.pause();
inView('.hero').on('enter', () => CABLES.patch.resume());
inView('.hero').on('exit', () => CABLES.patch.pause());
} }
} }
export default function init() { export default function init() {
new Canvas(); new Canvas();
}; }