javascript - css怎么解決hover鼠標(biāo)移除后的效果
問題描述
想要實現(xiàn)背景圖片鼠標(biāo)移入左右翻變換背景圖的動效,但是移出的時候想要去除掉翻轉(zhuǎn),直接把背景圖片換回來,搗鼓了許多都不知道這么弄,就大神臨摹求解。。。
<!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的時候有反轉(zhuǎn)的效果,而移開時直接變換沒有反轉(zhuǎn)?那你把transition這個屬性放在hover里就行了
回答2:效果預(yù)覽:http://codepen.io/zengkan0703...這是我實現(xiàn)的代碼,不知道是不是你想要的效果:
<!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>
實現(xiàn)原理其實很簡單,主要是用 css3 的過渡 transition。動畫分為兩步:
元素翻轉(zhuǎn) 180 度
在翻轉(zhuǎn)到 90 度的 時候,更換背景圖片的 url。
這里面需要注意的是,翻轉(zhuǎn)動畫的過渡時間曲線應(yīng)該用 “l(fā)inear”,這樣才能保證這個動畫是均勻進(jìn)行的,就能夠控制好翻轉(zhuǎn) 90 度的時機。
回答3:把transition寫在.flipBtn:hover{}里面 在.flipBtn{}加上transition:none;
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. html5 - javascript讀取自定義屬性的值,有的能夠取到,有的取不到怎么回事??3. html - Python2 BeautifulSoup 提取網(wǎng)頁中的表格數(shù)據(jù)及連接4. python - PyCharm里的一個文件不小心忽略了wx包5. android - VideoView與百度Map沖突6. python - (2006, ’MySQL server has gone away’)7. 小白學(xué)python的問題 關(guān)于%d和%s的區(qū)別8. python - 使用eclipse運行django代碼,修改了views.py這個文件,但是瀏覽器顯示的還是原有沒修改的結(jié)果,怎么處理?9. django - pycharm 如何配置 python3 的開發(fā)環(huán)境?10. win10 Apache24+PHP8.0,Apache不能正常加載php.ini。
