Skip to content

Commit

Permalink
#79 hide/show cursor at leaving/entering document.
Browse files Browse the repository at this point in the history
  • Loading branch information
artzub committed Mar 2, 2023
1 parent 80134e2 commit 5545bd3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/shared/components/FocusOverlay/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,35 @@ const FocusOverlay = ({ globalListener }) => {
[clickSoundPlay, clickSoundStop, globalListener, hoverSoundPlay, hoverSoundStop],
);

useEffect(
() => {
let isEnter = true;
const onDocumentEnter = () => {
if (!isEnter) {
console.log('show');
cursor.show();
isEnter = true;
}
};
const onDocumentLeave = () => {
if (isEnter) {
console.log('hide');
cursor.hide();
isEnter = false;
}
};

document.documentElement?.addEventListener('pointerenter', onDocumentEnter, true);
document.documentElement?.addEventListener('pointerleave', onDocumentLeave, true);

return () => {
document.documentElement?.removeEventListener('pointerenter', onDocumentEnter, true);
document.documentElement?.removeEventListener('pointerleave', onDocumentLeave, true);
};
},
[],
);

return null;
};

Expand Down
1 change: 1 addition & 0 deletions src/shared/graphics/Cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class Cursor extends PIXI.Container {
show() {
this.alpha = 0.001;
this._shadowMain
.attr('opacity', this.alpha)
.transition('fade')
.duration(duration)
.attr('opacity', 1);
Expand Down

0 comments on commit 5545bd3

Please sign in to comment.