javascript - css怎么解決hover鼠標移除后的效果
問題描述
想要實現背景圖片鼠標移入左右翻變換背景圖的動效,但是移出的時候想要去除掉翻轉,直接把背景圖片換回來,搗鼓了許多都不知道這么弄,就大神臨摹求解。。。
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>3D</title> <style> ul li{ list-style: none; cursor: pointer; position: relative; } .flipBtn, .flipBtn_face{ position: absolute; width:167px; height:116px; } .flipBtn {transition: transform 0.4s; transform-style: preserve-3d; cursor: pointer; position: relative; float: left; } .flipBtn_front{ backface-visibility: hidden; } .flipBtn_front{ width:151px; height:100px; margin:8px; background:url(./image/pic00.jpg) no-repeat; } .flipBtn_back{ width:151px; height:100px; margin:8px; background:url(./image/pic01.jpg) no-repeat; } .flipBtn_mid.flipBtn_face{ transform: rotateY(90deg); -webkit-transform: rotateY(90deg); -moz-transform: rotateY(90deg); } .flipBtn:hover{ transform:rotateY(-180deg); -webkit-transform: rotateY(-180deg); -moz-transform: rotateY(-180deg); } </style></head><body> <ul class='flipBtnWrapper'> <li class='flipBtn'> <a class='flipBtn_face flipBtn_back'></a> <p class='flipBtn_face flipBtn_mid'></p> <p class='flipBtn_face flipBtn_front'></p> </li> </ul></body></html>
問題解答
回答1:你是想hover的時候有反轉的效果,而移開時直接變換沒有反轉?那你把transition這個屬性放在hover里就行了
回答2:效果預覽:http://codepen.io/zengkan0703...這是我實現的代碼,不知道是不是你想要的效果:
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Document</title> <style> .box{ width: 200px; height: 200px; background:url(http://www.w3school.com.cn/i/site_photoref.jpg) no-repeat; transition: transform 0.5s linear ,background-image 0s 0.25s; background-size: cover; } .box:hover{ transform: rotateY(180deg); transform-origin: center; background-image: url(http://www.w3school.com.cn/i/site_photoqe.jpg); } </style></head><body> <p class='box'></p></body></html>
實現原理其實很簡單,主要是用 css3 的過渡 transition。動畫分為兩步:
元素翻轉 180 度
在翻轉到 90 度的 時候,更換背景圖片的 url。
這里面需要注意的是,翻轉動畫的過渡時間曲線應該用 “linear”,這樣才能保證這個動畫是均勻進行的,就能夠控制好翻轉 90 度的時機。
回答3:把transition寫在.flipBtn:hover{}里面 在.flipBtn{}加上transition:none;
相關文章:
1. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙2. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?3. linux運維 - python遠程控制windows如何實現4. Python2中code.co_kwonlyargcount的等效寫法5. python - 如何對列表中的列表進行頻率統計?6. django - Python error: [Errno 99] Cannot assign requested address7. mysql數據庫做關聯一般用id還是用戶名8. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?9. python小白,關于函數問題10. python小白 關于類里面的方法獲取變量失敗的問題
