准备两张素材照片,分别是点赞前和点赞后的图标,类似这样
html部分:
<template>
<div>
<div class="circle flex-h" @click="handleClick" :class="isUp?'check':''">
<div class="img-box" :class="isUp?'img-box-check':''">
<img v-if="isUp" src="../assets/icon/support1.png" alt="" />
<img v-else src="../assets/icon/support2.png" alt="" />
</div>
</div>
<div class="support-num">{{this.support}}</div>
</div>
</template>
js部分:
<script>
export default {
name: "test1",
components: {},
data () {
return {
isUp: false,
support:0
};
},
created () {
},
mounted () {
},
computed: {},
watch: {},
methods: {
handleClick () {
if(this.isUp==false)
this.support=this.support+1
else
this.support=this.support-1
this.isUp = !this.isUp
}
}
}
</script>
css部分:
<style scoped>
.circle {
position: absolute;
left: 10px;
top: 10px;
width: 50px;
height: 50px;
border-radius: 50%;
cursor: pointer;
box-shadow: 0px 0px 0px 0px rgba(223, 46, 58, 0.5)
}
.img-box {
position: absolute;
left: 50%;
top: 50%;
margin-left: -25px;
margin-top: -25px;
width: 50px;
height: 50px;
/*margin: 5px;*/
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none; /* 防止快速点击图片被选中,可不加,为提高体验,博主加上了这几行代码。*/
}
.check {
-webkit-transition: box-shadow 0.5s;
-moz-transition: box-shadow 0.5s;
-o-transition: box-shadow 0.5s;
transition: box-shadow 0.5s;
box-shadow: 0px 0px 0px 1em rgba(226, 32, 44, 0);
}
.img-box-check {
animation: anm 0.5s;
-moz-animation: anm 0.5s;
-webkit-animation: anm 0.5s;
-o-animation: anm 0.5s;
}
@keyframes anm {
0% {
transform: scale(0);
-webkit-transform: scale(0);
-moz-transform: scale(0);
}
50% {
transform: scale(1.3);
-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
}
100% {
transform: scale(1);
-webkit-transform: scale(1);
-moz-transform: scale(1);
}
}
/* 以下为处理兼容代码,可不看。*/
@-moz-keyframes anm {
0% {
transform: scale(0);
-webkit-transform: scale(0);
-moz-transform: scale(0);
}
50% {
transform: scale(1.3);
-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
}
100% {
transform: scale(1);
-webkit-transform: scale(1);
-moz-transform: scale(1);
}
}
@-webkit-keyframes anm {
0% {
transform: scale(0);
-webkit-transform: scale(0);
-moz-transform: scale(0);
}
50% {
transform: scale(1.3);
-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
}
100% {
transform: scale(1);
-webkit-transform: scale(1);
-moz-transform: scale(1);
}
}
@-o-keyframes anm {
0% {
transform: scale(0);
-webkit-transform: scale(0);
-moz-transform: scale(0);
}
50% {
transform: scale(1.3);
-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
}
100% {
transform: scale(1);
-webkit-transform: scale(1);
-moz-transform: scale(1);
}
}
.support-num{
position: absolute;
left: 80px;
top: 25px;
font-size: 25px;
}
</style>
效果:
点赞前
点赞过程
点赞
点赞后