vue实现点击翻转效果
lijiao 人气:0用vue简单实现一个点击翻转的效果:
1、
2、
3、
//html代码 测试 demo命名随便复制来的
<div class="Demo">
<div class="Before" :class="isTop ? 'contain-Before' : ''" @click="handleBefore"></div>
<div class="After" :class="isTop ? 'contain-After' : ''" @click="handleAfter" style="font-size:20px;color:black">这个是背面内容</div>
</div>
//在data中定义
isTop:false
//methods中的方法
handleBefore(){
if(!this.isTop){
this.isTop = true
}
},
handleAfter(){
if(this.isTop){
this.isTop = false
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//css
.Demo{
width: 375px;
height: 300px;
margin-top: 50px;
/* margin-left: 500px; */
position: relative;
perspective: 800px;
box-sizing: border-box;
}
.Before{
width: 100px;
height: 200px;
position: absolute;
top:0;
left: 0;
background-repeat: no-repeat;
background-position: center center;
backface-visibility: hidden;
transition: 1.5s;
background-image:url('../assets/images/chunfen4.jpg');
border:1px solid yellow;
}
.After{
width: 100px;
height: 200px;
position: absolute;
top:0;
left: 0;
color: #fff;
background-color:#fff;
text-indent: 2em;
transform: rotateY(-180deg);
backface-visibility: hidden;
transition: 1.5s;
border:1px solid yellow;
}
.Demo .contain-Before{
transform: rotateY(180deg);
}
.Demo .contain-After{
transform: rotateY(0deg);
}
大功告成,如果想要滑过翻转的话自行去掉事件,给div添加 :hover 方法
加载全部内容