滑鼠懸浮實現翻牌效果程式碼例項
本章節分享一段程式碼例項,它實現了滑鼠懸浮翻牌效果。
此效果比較常見於廣告,感興趣的朋友可以做一下參考,程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style type="text/css"> body { padding: 0; margin: 0; } .wrap { height: auto; width: 65%; margin: 100px auto; } .face { height: 200px; width: 200px; position: relative; overflow: hidden; float: left; margin: 2px; transform-style: preserve-3d; -webkit-transform-style: preserve-3d; } .face .box { height: 100%; width: 100%; position: absolute; left: 0; overflow: hidden; top: 0; z-index: 9999; transition: all ease 0.5s; -moz-transition: all ease 0.5s; -webkit-transition: all ease 0.5s; transform: rotate3d(0, 0, 0,0); -moz-transform: rotate3d(0, 0, 0,0); -webkit-transform: rotate3d(0, 0, 0,0); -ms-transform: rotate3d(0, 0, 0,0); backface-visibility: hidden; -moz-backface-visibility: hidden; -webkit-backface-visibility: hidden; } .face .box-mask { height: 100%; width: 100%; position: absolute; left: 0; top: 0; background: rgba(255,0,0,1); font-family: "微軟雅黑"; z-index: 999; backface-visibility: hidden; -moz-backface-visibility: hidden; -webkit-backface-visibility: hidden; transition: all ease 0.5s; -moz-transition: all ease 0.5s; -webkit-transition: all ease 0.5s; transform: rotate3d(0,1,0,-180deg); -moz-transform: rotate3d(0,1,0,-180deg); -ms-transform: rotate3d(0,1,0,-180deg); -webkit-transform: rotate3d(0,1,0,-180deg); } .face .box-mask p { color: white; padding: 0; text-align: center; margin: 0; font-size: 30px; line-height: 200px; } .face .mask { height: 100%; width: 100%; position: absolute; background: rgba(0,0,0,0.5); font-size: 30px; font-family: "微軟雅黑"; text-align: center; line-height: 200px; color: white; } .face img { height: 100%; width: 100%; } .face:hover .box { transform: rotate3d(0,1,0,-180deg); -moz-transform: rotate3d(0,1,0,-180deg); -ms-transform: rotate3d(0,1,0,-180deg); -webkit-transform: rotate3d(0,1,0,-180deg); z-index: 999; } .face:hover .box-mask { transform: rotate3d(0, 0,0,0); -moz-transform: rotate3d(0, 0, 0,0); -webkit-transform: rotate3d(0, 0, 0,0); -ms-transform: rotate3d(0, 0, 0,0); z-index: 9999; } </style> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type='text/javascript'> $(function() { $('.mask').css({ "left": "0", "top": "100%" }); $('.face').on('mouseenter', function(event) { var index = $(this).index(); var event = event || window.event, seenterX = event.clientX, seenterY = event.clientY; $(this).on('mouseleave', function(event) { var event = event || window.event, leaveX = event.clientX, leaveY = event.clientY, checkX = leaveX - seenterX, checkY = leaveY - seenterY; checkSeenter(checkX, checkY, index); }) }) function checkSeenter(checkX, checkY, index) { console.log(index) if (checkX > 0 && Math.abs(checkX) > Math.abs(checkY)) { console.log('左邊') $('.face').eq(index).find($('.mask')).css({ "left": "-100%", "top": "0" }).stop().animate({ "left": "100%", "top": "0%" }); } else if (checkX < 0 && Math.abs(checkX) > Math.abs(checkY)) { console.log('右邊'); $('.face').eq(index).find($('.mask')).css({ "left": "100%", "top": "0" }).stop().animate({ "left": "-100%", "top": "0%" }); } else if (checkY > 0 && Math.abs(checkX) <= Math.abs(checkY)) { console.log('上邊') $('.face').eq(index).find($('.mask')).css({ "left": "0", "top": "-100%" }).stop().animate({ "top": "100%", "left": "0" }); } else { console.log('下邊'); $('.face').eq(index).find($('.mask')).css({ "left": "0", "top": "100%" }).stop().animate({ "top": "-100%", "left": "0" }); } } }) </script> </head> <body> <div class="wrap"> <div class="face"> <div class="box"> <div class="mask">正面背景</div> <img src='demo/jQuery/img/41.jpg'> </div> <div class='box-mask'> <p>背面背景</p> </div> </div> <div class="face"> <div class="box"> <div class="mask">正面背景</div> <img src='demo/jQuery/img/40.jpg'> </div> <div class='box-mask'> <p>背面背景</p> </div> </div> <div class="face"> <div class="box"> <div class="mask">正面背景</div> <img src='demo/jQuery/img/39.jpg'> </div> <div class='box-mask'> <p>背面背景</p> </div> </div> <div class="face"> <div class="box"> <div class="mask">正面背景</div> <img src='demo/jQuery/img/38.jpg'> </div> <div class='box-mask'> <p>背面背景</p> </div> </div> </div> </body> </html>
相關文章
- 滑鼠懸浮實現抖動效果例項程式碼
- 滑鼠懸浮文字實現霓虹燈效果程式碼例項
- 滑鼠懸浮評分效果程式碼例項
- 滑鼠懸浮連結出現音效效果程式碼例項
- jQuery滑鼠懸浮翻牌效果詳解jQuery
- 滑鼠懸浮div實現旋轉縮放效果程式碼例項
- css滑鼠懸浮tips效果程式碼例項CSS
- css3程式碼實現的滑鼠懸浮按鈕效果程式碼例項CSSS3
- css3實現滑鼠懸浮劃過光弧效果程式碼例項CSSS3
- 滑鼠懸浮按鈕背景變色效果程式碼例項
- css3實現滑鼠懸浮圖示旋轉高亮效果程式碼例項CSSS3
- 滑鼠懸浮底部具有動態延伸條效果程式碼例項
- js文字內容感應滑鼠懸浮效果程式碼例項JS
- css滑鼠懸浮顏色動態填充效果程式碼例項CSS
- CSS3實現的滑鼠懸浮文字顏色漸變效果程式碼例項CSSS3
- 滑鼠懸浮彈出滑鼠跟隨層程式碼例項
- javascript滑鼠懸浮行變色程式碼例項JavaScript
- 滑鼠懸浮連結彈出提示程式碼例項
- 滑鼠懸浮div實現旋轉效果
- 滑鼠懸浮出現tips提示框效果程式碼例項
- 滑鼠懸浮改變連結樣式程式碼例項
- 滑鼠懸浮實現環形旋轉效果
- 滑鼠懸浮圖片實現翻轉效果
- 滑鼠懸浮圖片實現縮放效果
- 滑鼠懸浮可以伸縮的搜尋框程式碼例項
- 自定義滑鼠懸浮連結彈出提示程式碼例項
- 滑鼠懸浮實現連結背景變色效果
- js滑鼠懸浮字串實現字串跳動效果JS字串
- javascript實現滑鼠懸浮圖片實現抖動效果JavaScript
- 滑鼠懸浮出現下拉選單程式碼例項
- [譯] CSS 變數實現炫酷滑鼠懸浮效果CSS變數
- 實現滑鼠懸浮table表格行背景變色效果
- 滑鼠懸浮實現圖片動畫上下切換效果動畫
- 滑鼠懸浮於連結<a>之上出現提示文字效果程式碼
- CSS實現的滑鼠懸浮整行背景變色程式碼CSS
- 滑鼠滑過實現淡入淡出效果程式碼例項
- css3實現滑鼠懸浮背景上下翻滾效果CSSS3
- css3實現的滑鼠懸浮按鈕動畫效果CSSS3動畫