How do I invoke the animation again when state stays the same










1














I am figuring out how I can re-animate the shake animation on an incorrect answer. Or the flash animation on a correct answer.



I defined 2 booleans as a state for the correct answer and I understand that if I enter the same incorrect answer the incorrect flash stays false. But how do I fix that the shake animations kicks in another time.



I made a fiddle, the correct code is '1234'. When you first fail to enter, the shake animation kicks in. Same is for the correct answer. Only the first time the animations shows.



How can I invoke the animations again when correct or incorrect answers are given.



<div class="alert alert-danger animated" 
v-bind:class=" 'shake': incorrect "
v-if="incorrect">
Code is incorrect
</div>


https://jsfiddle.net/mrklein/05sfmuc2/



new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
,
methods:
checkpwd: function(todo)
if (this.modelcode == this.code)
this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;




);









share|improve this question





















  • I see you're using animate.css with vue.js. I'd recommend you looking into use Vue transitions vuejs.org/v2/guide/transitions.html and perhaps github.com/asika32764/vue2-animate, as you have to keep the state of your animations in the logic of your code.
    – cal_br_mar
    Nov 9 at 21:09















1














I am figuring out how I can re-animate the shake animation on an incorrect answer. Or the flash animation on a correct answer.



I defined 2 booleans as a state for the correct answer and I understand that if I enter the same incorrect answer the incorrect flash stays false. But how do I fix that the shake animations kicks in another time.



I made a fiddle, the correct code is '1234'. When you first fail to enter, the shake animation kicks in. Same is for the correct answer. Only the first time the animations shows.



How can I invoke the animations again when correct or incorrect answers are given.



<div class="alert alert-danger animated" 
v-bind:class=" 'shake': incorrect "
v-if="incorrect">
Code is incorrect
</div>


https://jsfiddle.net/mrklein/05sfmuc2/



new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
,
methods:
checkpwd: function(todo)
if (this.modelcode == this.code)
this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;




);









share|improve this question





















  • I see you're using animate.css with vue.js. I'd recommend you looking into use Vue transitions vuejs.org/v2/guide/transitions.html and perhaps github.com/asika32764/vue2-animate, as you have to keep the state of your animations in the logic of your code.
    – cal_br_mar
    Nov 9 at 21:09













1












1








1







I am figuring out how I can re-animate the shake animation on an incorrect answer. Or the flash animation on a correct answer.



I defined 2 booleans as a state for the correct answer and I understand that if I enter the same incorrect answer the incorrect flash stays false. But how do I fix that the shake animations kicks in another time.



I made a fiddle, the correct code is '1234'. When you first fail to enter, the shake animation kicks in. Same is for the correct answer. Only the first time the animations shows.



How can I invoke the animations again when correct or incorrect answers are given.



<div class="alert alert-danger animated" 
v-bind:class=" 'shake': incorrect "
v-if="incorrect">
Code is incorrect
</div>


https://jsfiddle.net/mrklein/05sfmuc2/



new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
,
methods:
checkpwd: function(todo)
if (this.modelcode == this.code)
this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;




);









share|improve this question













I am figuring out how I can re-animate the shake animation on an incorrect answer. Or the flash animation on a correct answer.



I defined 2 booleans as a state for the correct answer and I understand that if I enter the same incorrect answer the incorrect flash stays false. But how do I fix that the shake animations kicks in another time.



I made a fiddle, the correct code is '1234'. When you first fail to enter, the shake animation kicks in. Same is for the correct answer. Only the first time the animations shows.



How can I invoke the animations again when correct or incorrect answers are given.



<div class="alert alert-danger animated" 
v-bind:class=" 'shake': incorrect "
v-if="incorrect">
Code is incorrect
</div>


https://jsfiddle.net/mrklein/05sfmuc2/



new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
,
methods:
checkpwd: function(todo)
if (this.modelcode == this.code)
this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;




);






vue.js animate.css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 20:54









MrKlein

282




282











  • I see you're using animate.css with vue.js. I'd recommend you looking into use Vue transitions vuejs.org/v2/guide/transitions.html and perhaps github.com/asika32764/vue2-animate, as you have to keep the state of your animations in the logic of your code.
    – cal_br_mar
    Nov 9 at 21:09
















  • I see you're using animate.css with vue.js. I'd recommend you looking into use Vue transitions vuejs.org/v2/guide/transitions.html and perhaps github.com/asika32764/vue2-animate, as you have to keep the state of your animations in the logic of your code.
    – cal_br_mar
    Nov 9 at 21:09















I see you're using animate.css with vue.js. I'd recommend you looking into use Vue transitions vuejs.org/v2/guide/transitions.html and perhaps github.com/asika32764/vue2-animate, as you have to keep the state of your animations in the logic of your code.
– cal_br_mar
Nov 9 at 21:09




I see you're using animate.css with vue.js. I'd recommend you looking into use Vue transitions vuejs.org/v2/guide/transitions.html and perhaps github.com/asika32764/vue2-animate, as you have to keep the state of your animations in the logic of your code.
– cal_br_mar
Nov 9 at 21:09












1 Answer
1






active

oldest

votes


















2














What you need to do is have another variable be the control for the animation. You'd reset that variable after the duration of the animation. I just put 1000 ms in my example. You may need to debounce a double click if you really want it to be perfect (ie, if they click while the animation is going on, you don't really want to do another animation but maybe you do?).



https://jsfiddle.net/lucuma/zawk41gh/



<div id="app" class="card" style="width:18rem;">
<div class="card-body">

<div class="alert alert-danger animated"
v-bind:class=" 'shake': runAnimate "
v-if="incorrect">
Code is incorrect
</div>

<div class="alert alert-success animated"
v-bind:class=" 'flash': runAnimate "
v-if="correct">
Correct code entered
</div>

<input v-model="modelcode" placeholder="password" class="form-control">
<button class="btn btn-primary mt-3" @click="checkpwd">check</button>
correct code is 1234
</div>
</div>


new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
runAnimate: false
,
methods:
checkpwd: function(todo)
this.runAnimate= true;
if (this.modelcode == this.code)

this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;

setTimeout(()=> this.runAnimate = false, 1000);



);





share|improve this answer






















  • Thanks, always have the feeling using setTimeout for these kind of situations is a kind of a hack. But it works.
    – MrKlein
    Nov 11 at 12:54










  • You need to delay the resetting of the animation (removing the variable) for the length of the animation. Nothing wrong with the setTimeout per se.
    – lucuma
    Nov 12 at 13:50











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233139%2fhow-do-i-invoke-the-animation-again-when-state-stays-the-same%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














What you need to do is have another variable be the control for the animation. You'd reset that variable after the duration of the animation. I just put 1000 ms in my example. You may need to debounce a double click if you really want it to be perfect (ie, if they click while the animation is going on, you don't really want to do another animation but maybe you do?).



https://jsfiddle.net/lucuma/zawk41gh/



<div id="app" class="card" style="width:18rem;">
<div class="card-body">

<div class="alert alert-danger animated"
v-bind:class=" 'shake': runAnimate "
v-if="incorrect">
Code is incorrect
</div>

<div class="alert alert-success animated"
v-bind:class=" 'flash': runAnimate "
v-if="correct">
Correct code entered
</div>

<input v-model="modelcode" placeholder="password" class="form-control">
<button class="btn btn-primary mt-3" @click="checkpwd">check</button>
correct code is 1234
</div>
</div>


new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
runAnimate: false
,
methods:
checkpwd: function(todo)
this.runAnimate= true;
if (this.modelcode == this.code)

this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;

setTimeout(()=> this.runAnimate = false, 1000);



);





share|improve this answer






















  • Thanks, always have the feeling using setTimeout for these kind of situations is a kind of a hack. But it works.
    – MrKlein
    Nov 11 at 12:54










  • You need to delay the resetting of the animation (removing the variable) for the length of the animation. Nothing wrong with the setTimeout per se.
    – lucuma
    Nov 12 at 13:50
















2














What you need to do is have another variable be the control for the animation. You'd reset that variable after the duration of the animation. I just put 1000 ms in my example. You may need to debounce a double click if you really want it to be perfect (ie, if they click while the animation is going on, you don't really want to do another animation but maybe you do?).



https://jsfiddle.net/lucuma/zawk41gh/



<div id="app" class="card" style="width:18rem;">
<div class="card-body">

<div class="alert alert-danger animated"
v-bind:class=" 'shake': runAnimate "
v-if="incorrect">
Code is incorrect
</div>

<div class="alert alert-success animated"
v-bind:class=" 'flash': runAnimate "
v-if="correct">
Correct code entered
</div>

<input v-model="modelcode" placeholder="password" class="form-control">
<button class="btn btn-primary mt-3" @click="checkpwd">check</button>
correct code is 1234
</div>
</div>


new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
runAnimate: false
,
methods:
checkpwd: function(todo)
this.runAnimate= true;
if (this.modelcode == this.code)

this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;

setTimeout(()=> this.runAnimate = false, 1000);



);





share|improve this answer






















  • Thanks, always have the feeling using setTimeout for these kind of situations is a kind of a hack. But it works.
    – MrKlein
    Nov 11 at 12:54










  • You need to delay the resetting of the animation (removing the variable) for the length of the animation. Nothing wrong with the setTimeout per se.
    – lucuma
    Nov 12 at 13:50














2












2








2






What you need to do is have another variable be the control for the animation. You'd reset that variable after the duration of the animation. I just put 1000 ms in my example. You may need to debounce a double click if you really want it to be perfect (ie, if they click while the animation is going on, you don't really want to do another animation but maybe you do?).



https://jsfiddle.net/lucuma/zawk41gh/



<div id="app" class="card" style="width:18rem;">
<div class="card-body">

<div class="alert alert-danger animated"
v-bind:class=" 'shake': runAnimate "
v-if="incorrect">
Code is incorrect
</div>

<div class="alert alert-success animated"
v-bind:class=" 'flash': runAnimate "
v-if="correct">
Correct code entered
</div>

<input v-model="modelcode" placeholder="password" class="form-control">
<button class="btn btn-primary mt-3" @click="checkpwd">check</button>
correct code is 1234
</div>
</div>


new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
runAnimate: false
,
methods:
checkpwd: function(todo)
this.runAnimate= true;
if (this.modelcode == this.code)

this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;

setTimeout(()=> this.runAnimate = false, 1000);



);





share|improve this answer














What you need to do is have another variable be the control for the animation. You'd reset that variable after the duration of the animation. I just put 1000 ms in my example. You may need to debounce a double click if you really want it to be perfect (ie, if they click while the animation is going on, you don't really want to do another animation but maybe you do?).



https://jsfiddle.net/lucuma/zawk41gh/



<div id="app" class="card" style="width:18rem;">
<div class="card-body">

<div class="alert alert-danger animated"
v-bind:class=" 'shake': runAnimate "
v-if="incorrect">
Code is incorrect
</div>

<div class="alert alert-success animated"
v-bind:class=" 'flash': runAnimate "
v-if="correct">
Correct code entered
</div>

<input v-model="modelcode" placeholder="password" class="form-control">
<button class="btn btn-primary mt-3" @click="checkpwd">check</button>
correct code is 1234
</div>
</div>


new Vue(
el: "#app",
data:
correct: false,
incorrect: false,
code: '1234',
modelcode: '',
runAnimate: false
,
methods:
checkpwd: function(todo)
this.runAnimate= true;
if (this.modelcode == this.code)

this.correct = true;
this.incorrect = false;
else
this.correct = false;
this.incorrect = true;

setTimeout(()=> this.runAnimate = false, 1000);



);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 21:39

























answered Nov 9 at 21:21









lucuma

16.8k45479




16.8k45479











  • Thanks, always have the feeling using setTimeout for these kind of situations is a kind of a hack. But it works.
    – MrKlein
    Nov 11 at 12:54










  • You need to delay the resetting of the animation (removing the variable) for the length of the animation. Nothing wrong with the setTimeout per se.
    – lucuma
    Nov 12 at 13:50

















  • Thanks, always have the feeling using setTimeout for these kind of situations is a kind of a hack. But it works.
    – MrKlein
    Nov 11 at 12:54










  • You need to delay the resetting of the animation (removing the variable) for the length of the animation. Nothing wrong with the setTimeout per se.
    – lucuma
    Nov 12 at 13:50
















Thanks, always have the feeling using setTimeout for these kind of situations is a kind of a hack. But it works.
– MrKlein
Nov 11 at 12:54




Thanks, always have the feeling using setTimeout for these kind of situations is a kind of a hack. But it works.
– MrKlein
Nov 11 at 12:54












You need to delay the resetting of the animation (removing the variable) for the length of the animation. Nothing wrong with the setTimeout per se.
– lucuma
Nov 12 at 13:50





You need to delay the resetting of the animation (removing the variable) for the length of the animation. Nothing wrong with the setTimeout per se.
– lucuma
Nov 12 at 13:50


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233139%2fhow-do-i-invoke-the-animation-again-when-state-stays-the-same%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)