From 7e7335ef7c426c2b4ca7773d6966a3160869614b Mon Sep 17 00:00:00 2001 From: Anatoly Date: Sun, 30 Jan 2022 12:08:44 +0300 Subject: [PATCH] Fixed bug with rapid mouse movement --- bundle/vue-three-d-mockup.esm.js | 9 +++++++-- src/Mockup.vue | 6 +++++- src/MockupModel.js | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bundle/vue-three-d-mockup.esm.js b/bundle/vue-three-d-mockup.esm.js index c222e0e..3676ccd 100644 --- a/bundle/vue-three-d-mockup.esm.js +++ b/bundle/vue-three-d-mockup.esm.js @@ -9,6 +9,7 @@ class MockupModel extends Group { this.animation = this.floatAnim; this.goingHome = false; + this.homeTimeout = null; this.home = home; this.reset(); @@ -55,7 +56,7 @@ class MockupModel extends Group { this.rotSpeed.y = (this.home.rotation.y - this.rotation.y) / rT; this.rotSpeed.z = (this.home.rotation.z - this.rotation.z) / rT; - setTimeout(() => { + this.homeTimeout = setTimeout(() => { this.goingHome = false; this.reset(); this.startFloat(); @@ -277,7 +278,11 @@ var script = { } function handleMouseEnter() { - if (phone) { phone.animation = phone.lookAtAnim; } + if (phone) { + phone.animation = phone.lookAtAnim; + phone.goingHome = false; + clearTimeout(phone.homeTimeout); + } } function handleMouseLeave() { diff --git a/src/Mockup.vue b/src/Mockup.vue index 64ee22b..bf60341 100644 --- a/src/Mockup.vue +++ b/src/Mockup.vue @@ -169,7 +169,11 @@ export default { } function handleMouseEnter() { - if (phone) { phone.animation = phone.lookAtAnim; } + if (phone) { + phone.animation = phone.lookAtAnim; + phone.goingHome = false; + clearTimeout(phone.homeTimeout); + } } function handleMouseLeave() { diff --git a/src/MockupModel.js b/src/MockupModel.js index 38b7570..3b12426 100644 --- a/src/MockupModel.js +++ b/src/MockupModel.js @@ -6,6 +6,7 @@ export default class MockupModel extends Group { this.animation = this.floatAnim; this.goingHome = false; + this.homeTimeout = null; this.home = home; this.reset(); @@ -52,7 +53,7 @@ export default class MockupModel extends Group { this.rotSpeed.y = (this.home.rotation.y - this.rotation.y) / rT; this.rotSpeed.z = (this.home.rotation.z - this.rotation.z) / rT; - setTimeout(() => { + this.homeTimeout = setTimeout(() => { this.goingHome = false; this.reset(); this.startFloat();