华域联盟 JAVA vue实现点击翻转效果

vue实现点击翻转效果

用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
     }
 }
//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 方法

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持华域联盟。

您可能感兴趣的文章:

本文由 华域联盟 原创撰写:华域联盟 » vue实现点击翻转效果

转载请保留出处和原文链接:https://www.cnhackhy.com/76639.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部