I want a div to flash in case a user clicks on it. Is there a solution without manually running setTimeout?
Solution with setTimeout:
app.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
<style>
div { transition: background-color 1s; }
div.flashing { background-color: green; transition: none; }
</style>
<div id="app" :class="{'flashing':flashing}" v-on:click="flash">flash when clicked</div>
app.js
const data = { flashing: false }
new Vue({
el: '#app',
data,
methods: { flash }
})
function flash() {
data.flashing = true;
setTimeout(() => data.flashing = false, 100);
}
Js Fiddle: https://jsfiddle.net/ang3ukg2/
:active?