mirror of
https://github.com/Xevion/power-math.git
synced 2025-12-14 12:12:33 -06:00
remove toast notifications for green feedback & red shake, use animate.css for fly fade in/out/right
This commit is contained in:
81
src/App.vue
81
src/App.vue
@@ -1,11 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div id="expression" v-katex="expression"></div>
|
<div id="expression" class="animate__animated animate__faster" :class="currentAnimation" v-katex="expression"></div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="columns is-centered">
|
<div class="columns is-centered">
|
||||||
<div class="column is-three-fifths">
|
<div class="column is-three-fifths">
|
||||||
<b-field id="input" @keyup.native.enter="checkAnswer()">
|
<b-field id="input" @keyup.native.enter="checkAnswer()">
|
||||||
<b-input :custom-class="input_shake" v-model="answer"></b-input>
|
<b-input :custom-class="inputClass" v-model="answer"></b-input>
|
||||||
</b-field>
|
</b-field>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -80,21 +80,23 @@ export default {
|
|||||||
answer: null,
|
answer: null,
|
||||||
currentQuestion: null,
|
currentQuestion: null,
|
||||||
correctTimeout: false,
|
correctTimeout: false,
|
||||||
shakeInput: false
|
inputClass: false,
|
||||||
|
allowInputSubmit: true,
|
||||||
|
currentAnimation: null,
|
||||||
|
chances: 3
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
expression() {
|
expression() {
|
||||||
return this.currentQuestion != null ? this.currentQuestion.text : "error";
|
return this.currentQuestion != null ? this.currentQuestion.text : "error";
|
||||||
},
|
|
||||||
input_shake() {
|
|
||||||
return this.shakeInput ? "shake" : "";
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
window.addEventListener('keyup', (e) => {
|
window.addEventListener('keyup', (e) => {
|
||||||
if (e.keyCode === 39) {
|
if (e.keyCode === 38) {
|
||||||
this.nextQuestion();
|
this.nextQuestion();
|
||||||
|
} else if (e.keyCode === 39) {
|
||||||
|
this.checkAnswer(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -104,10 +106,32 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
nextQuestion() {
|
nextQuestion(fail = false) {
|
||||||
this.currentQuestion = arithmetic.methods.getProblem();
|
let problem = arithmetic.methods.getProblem();
|
||||||
|
if (this.currentQuestion == null)
|
||||||
|
this.currentQuestion = problem;
|
||||||
|
else {
|
||||||
|
// Animate fade out
|
||||||
|
if (fail)
|
||||||
|
this.currentAnimation = 'animate__fadeOutRight'
|
||||||
|
else
|
||||||
|
this.currentAnimation = 'animate__fadeOutUp';
|
||||||
|
|
||||||
|
// Fade in down
|
||||||
|
setTimeout(() => {
|
||||||
|
this.currentQuestion = problem;
|
||||||
|
this.currentAnimation = 'animate__fadeInDown';
|
||||||
|
setTimeout(() => {
|
||||||
|
this.currentAnimation = '';
|
||||||
|
}, 500)
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
checkAnswer() {
|
checkAnswer(force = false) {
|
||||||
|
// Skip answer checking if answer submission currently locked
|
||||||
|
if (!this.allowInputSubmit && !force)
|
||||||
|
return;
|
||||||
|
|
||||||
// Check answer
|
// Check answer
|
||||||
let correct;
|
let correct;
|
||||||
// Number parsing if the answer is a specific number
|
// Number parsing if the answer is a specific number
|
||||||
@@ -117,30 +141,33 @@ export default {
|
|||||||
// String based answer (like a fraction)
|
// String based answer (like a fraction)
|
||||||
correct = this.currentQuestion.answer === this.answer
|
correct = this.currentQuestion.answer === this.answer
|
||||||
|
|
||||||
if (correct) {
|
if (correct || force) {
|
||||||
// Correct answer toast, new question & reset answer box
|
// Correct answer animation, new question & reset answer box
|
||||||
this.$buefy.toast.open({
|
this.inputClass = 'correct';
|
||||||
message: 'Correct!',
|
setTimeout(this.clearInputClass, 500)
|
||||||
type: 'is-success',
|
|
||||||
duration: 600
|
|
||||||
})
|
|
||||||
this.nextQuestion();
|
this.nextQuestion();
|
||||||
this.answer = "";
|
this.answer = "";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Incorrect answer toast
|
if (--this.chances === 0) {
|
||||||
this.$buefy.toast.open({
|
this.nextQuestion(true);
|
||||||
message: 'Incorrect.',
|
this.chances = 3;
|
||||||
type: 'is-danger',
|
}
|
||||||
duration: 500
|
|
||||||
})
|
|
||||||
|
|
||||||
// Shake input
|
// Shake input
|
||||||
this.shakeInput = true;
|
this.inputClass = 'incorrect';
|
||||||
setTimeout(this.stopShake, 500);
|
setTimeout(this.clearInputClass, 500);
|
||||||
|
|
||||||
|
// Lock submission
|
||||||
|
this.allowInputSubmit = false;
|
||||||
|
setTimeout(this.unlockInput, 500)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
stopShake() {
|
clearInputClass() {
|
||||||
this.shakeInput = false;
|
this.inputClass = '';
|
||||||
|
},
|
||||||
|
unlockInput() {
|
||||||
|
this.allowInputSubmit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import Buefy from 'buefy';
|
|||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import 'katex/dist/katex.min.css';
|
import 'katex/dist/katex.min.css';
|
||||||
import 'buefy/dist/buefy.css';
|
import 'buefy/dist/buefy.css';
|
||||||
|
import 'animate.css/animate.min.css';
|
||||||
|
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
|||||||
@@ -22,6 +22,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#input input.shake {
|
@keyframes green_flash {
|
||||||
animation: shake 0.5s;
|
0% {
|
||||||
|
border-color: hsl(0, 0%, 20%);
|
||||||
|
//border-color: rgba(#41df5b, 2.5%);
|
||||||
|
}
|
||||||
|
60% {
|
||||||
|
border-color: rgba(#41df5b, 5%);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
border-color: hsl(0, 0%, 20%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#input input.incorrect {
|
||||||
|
animation: shake 0.5s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
#input input.correct {
|
||||||
|
animation: green_flash 0.5s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user