Merge pull request #20 from wswidzinski/stop-canvas-offscreen

Stop canvases that are not in viewport
This commit is contained in:
Maciej Matuszewski 2018-01-17 23:53:37 +01:00 committed by GitHub
commit 97f5b80aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 3 deletions

View File

@ -1,14 +1,29 @@
/* eslint-disable */
import inView from 'in-view';
class Canvas {
constructor() {
this.connect = new CABLES.Patch({
this.initConnectCanvas();
this.initKleinCanvas();
}
initConnectCanvas() {
const connect = new CABLES.Patch({
patchFile: 'assets/connect.json',
prefixAssetPath: '',
glCanvasId: 'connect',
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(
'klein',
{
@ -17,9 +32,14 @@ class Canvas {
silent: true
}
)
CABLES.patch.pause();
inView('.hero').on('enter', () => CABLES.patch.resume());
inView('.hero').on('exit', () => CABLES.patch.pause());
}
}
export default function init() {
new Canvas();
};
}