122 lines
2.4 KiB
Vue
122 lines
2.4 KiB
Vue
<template>
|
|
<div class="counter">
|
|
<div class="count-top">
|
|
<label class="upper-label" for="limit" @click="reset">Limit</label>
|
|
<input class="upper-input" name="limit" type="number" v-model="countBound" placeholder="10"/>
|
|
</div>
|
|
<div @click="bumpCount" :style="countStyle" class="count-bottom">
|
|
<div class="value">{{ countCurrent }}</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate
|
|
|
|
export default {
|
|
name: 'counter',
|
|
data () {
|
|
return {
|
|
countBound: 15,
|
|
countCurrent: 0,
|
|
limitReached: false,
|
|
countStyle: {
|
|
backgroundColor: '#179e63',
|
|
color: '#FFFFFF'
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
bumpCount () {
|
|
if (this.limitReached) {
|
|
this.countCurrent = 0
|
|
this.limitReached = false
|
|
} else {
|
|
this.countCurrent = this.countCurrent + 1
|
|
}
|
|
|
|
this.limitReached = (this.countCurrent >= this.countBound)
|
|
|
|
if (this.limitReached) {
|
|
this.countStyle.backgroundColor = '#e53232'
|
|
window.navigator.vibrate([200, 100, 200])
|
|
} else {
|
|
this.countStyle.backgroundColor = '#179e63'
|
|
}
|
|
},
|
|
reset () {
|
|
this.countCurrent = 0;
|
|
this.limitReached = false;
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
<style>
|
|
|
|
.counter {
|
|
margin: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.count-top {
|
|
width:100%;
|
|
min-height:20%;
|
|
font-size: 3em;
|
|
display: flex;
|
|
justify-content: flex-start;
|
|
vertical-align: bottom;
|
|
}
|
|
.upper-label {
|
|
flex: 0 0 auto;
|
|
vertical-align: text-bottom;
|
|
align-self: flex-end;
|
|
margin-bottom: 0.55em;
|
|
}
|
|
.upper-input {
|
|
font-size: 1em;
|
|
width: 3em;
|
|
flex: 1 1 auto;
|
|
margin: 0.2em;
|
|
}
|
|
|
|
.count-bottom {
|
|
width:100%;
|
|
min-height:70%;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
-webkit-touch-callout: none;
|
|
-webkit-user-select: none;
|
|
-khtml-user-select: none;
|
|
-moz-user-select: none;
|
|
-ms-user-select: none;
|
|
user-select: none;
|
|
}
|
|
.value {
|
|
font-family: -apple-system-tall-body, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
flex: 0 0 auto;
|
|
font-size: 10em;
|
|
}
|
|
|
|
h1, h2 {
|
|
font-weight: normal;
|
|
}
|
|
|
|
ul {
|
|
list-style-type: none;
|
|
padding: 0;
|
|
}
|
|
|
|
li {
|
|
display: inline-block;
|
|
margin: 0 10px;
|
|
}
|
|
|
|
a {
|
|
color: #35495E;
|
|
}
|
|
</style>
|