javascript - css怎么解決hover鼠標(biāo)移除后的效果
問(wèn)題描述
想要實(shí)現(xiàn)背景圖片鼠標(biāo)移入左右翻變換背景圖的動(dòng)效,但是移出的時(shí)候想要去除掉翻轉(zhuǎn),直接把背景圖片換回來(lái),搗鼓了許多都不知道這么弄,就大神臨摹求解。。。
<!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>
問(wèn)題解答
回答1:你是想hover的時(shí)候有反轉(zhuǎn)的效果,而移開(kāi)時(shí)直接變換沒(méi)有反轉(zhuǎn)?那你把transition這個(gè)屬性放在hover里就行了
回答2:效果預(yù)覽:http://codepen.io/zengkan0703...這是我實(shí)現(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>
實(shí)現(xiàn)原理其實(shí)很簡(jiǎn)單,主要是用 css3 的過(guò)渡 transition。動(dòng)畫(huà)分為兩步:
元素翻轉(zhuǎn) 180 度
在翻轉(zhuǎn)到 90 度的 時(shí)候,更換背景圖片的 url。
這里面需要注意的是,翻轉(zhuǎn)動(dòng)畫(huà)的過(guò)渡時(shí)間曲線(xiàn)應(yīng)該用 “l(fā)inear”,這樣才能保證這個(gè)動(dòng)畫(huà)是均勻進(jìn)行的,就能夠控制好翻轉(zhuǎn) 90 度的時(shí)機(jī)。
回答3:把transition寫(xiě)在.flipBtn:hover{}里面 在.flipBtn{}加上transition:none;
相關(guān)文章:
1. docker-compose中volumes的問(wèn)題2. boot2docker無(wú)法啟動(dòng)3. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””4. nignx - docker內(nèi)nginx 80端口被占用5. java - SSH框架中寫(xiě)分頁(yè)時(shí)service層中不能注入分頁(yè)類(lèi)6. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.7. javascript - mock.js可以存儲(chǔ)數(shù)據(jù)嗎8. golang - 用IDE看docker源碼時(shí)的小問(wèn)題9. docker api 開(kāi)發(fā)的端口怎么獲取?10. dockerfile - 為什么docker容器啟動(dòng)不了?

網(wǎng)公網(wǎng)安備