vue實現點選翻轉效果
阿新 • • 發佈:2021-07-26
用簡單實現一個點選翻轉的效果,供大家參考,具體內容如下
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="hanoccpqSdleAfter" 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 } }
// .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-visibwww.cppcns.comility: hidden; transition: 1.5s; background-image:url('../assets/images/chunfen4.jpg'); border:1px solid yellow; } .After{ width: 100px; height: 200px; poshttp://www.cppcns.comition: 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{http://www.cppcns.comtransform: rotateY(0deg); }
大功告成,如果想要滑過翻轉的話自行去掉事件,給div新增 :hover 方法
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。