From 8801b8c02024ae96081c727792e26577dd2b12e4 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 10 Oct 2022 16:29:42 +0200 Subject: [PATCH] feat: skip type writing animation before 10min has passed --- src/components/Home.vue | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/components/Home.vue b/src/components/Home.vue index aeeae4b..3c83478 100644 --- a/src/components/Home.vue +++ b/src/components/Home.vue @@ -50,6 +50,25 @@ } protected mounted() { + let last = 0; + + // check if already animated in the last 10 min + const typed = localStorage.getItem('typed') + const parsed = parseInt(typed!) as number + if( !isNaN(parsed) ){ + last = parsed; + } + + const now = new Date().getTime(); + const diff_sec = (now - last) / 1e3; + + const threshold = 10 * 60; + + // skip animation if already done less than 10min ago + if( diff_sec < threshold ){ + return; + } + const t1 = new TypeWriter( this.$refs['text1'] as HTMLElement ) const t2 = new TypeWriter( this.$refs['text2'] as HTMLElement ) const t3 = new TypeWriter( this.$refs['text3'] as HTMLElement ) @@ -68,6 +87,11 @@ setTimeout( () => t3.animate(4000), 6000 ); // wait 10s, anim 3s setTimeout( () => t4.animate(3000), 10000 ); + + // local storage: store that we animated once + setTimeout( () => { + localStorage.setItem('typed', `${new Date().getTime()}`); + }, 13000 ); } }