JSFiddle - React, Tailwind, and code Playground
by squarified
HTML
<script src="https://npmcdn.com/vue/dist/vue.js"></script>
<div id="exercise">
<!-- 1) Start the Effect with the Button. The Effect should alternate the "highlight" or "shrink" class on each new setInterval tick (attach respective class to the div with id "effect" below) -->
<div>
<button @click="startEffect">Start Effect</button>
<div id="effect" :class="currentEffect"></div>
</div>
<!-- 2) Create a couple of CSS classes and attach them via the array syntax -->
<div :class="[a, b, c]">I got no class :(</div>
<!-- 3) Let the user enter a class (create some example classes) and attach it -->
<div>
<input type="text" v-model="hejsan">
<div></div>
</div>
</div>
CSS
#effect {
width: 100px;
height: 100px;
border: 1px solid black;
}
.highlight {
background-color: red;
width: 200px !important;
}
.shrink {
background-color: gray;
width: 50px !important;
}
.hannes {
width: 200px;
height: 200px;
}
.pannes {
background-color: yellow;
}
.pepparrot {
border: 1px solid red;
}
JavaScript
new Vue({
el: '#exercise',
data: {
currentEffect: '',
a: 'hannes',
b: 'pannes',
c: 'pepparrot',
hejsan: 'hannes'
},
methods: {
startEffect: function() {
let that = this;
setInterval(function() {
that.currentEffect = that.currentEffect === 'highlight' ?
'shrink' : 'highlight';
}, 20000);
}
}
});