jQuery實現(xiàn)撲克正反面翻牌效果
更新時間:2017年03月10日 15:13:52 作者:一者乎
本篇文章主要介紹了jQuery實現(xiàn)撲克正反面翻牌效果的實例。具有很好的參考價值。下面跟著小編一起來看下吧
效果圖:
代碼如下:
<!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>【JQuery插件】撲克正反面翻牌效果</title> <style> *{margin:0px;padding:0px;list-style:none;font-size: 16px;} </style> </head> <body> <style> .demo1 {margin:10px; width: 200px;height: 100px;text-align: center;position: relative;} .demo1 .front{width: 200px;height: 100px;position:absolute;left:0px;top:0px;background-color: #000;color: #fff;} .demo1 .behind{width: 200px;height: 0px;position:absolute;left:0px;top:50px;background-color: #ccc;color: #000;display: none;} </style> <h1>demo1 y軸 (css布局提示:背面默認隱藏 height為0 top是高度的一半也就是demo中間)</h1> <div class="demo1"> <div class="front">正面正面正<br/>面正面正面<br/></div> <div class="behind">背面</div> </div> <div class="demo1"> <div class="front">正面</div> <div class="behind">背面</div> </div> <style> .demo2 {margin:10px; width: 200px;height: 100px;text-align: center;position: relative;} .demo2 .front{width: 200px;z-index: 1; height: 100px;position:absolute;left:0px;top:0px;background-color: #000;color: #fff;} .demo2 .behind{width: 0;height: 100px;z-index: 0;position:absolute;left:100px;top:0;background-color: #ccc;color: #000;} </style> <h1>demo2 x軸(css布局提示:背面默認隱藏 width為0 left是寬度的一半也就是demo中間)</h1> <div class="demo2"> <div class="front">正面</div> <div class="behind">背面</div> </div> <div class="demo2"> <div class="front">正面</div> <div class="behind">背面</div> </div> <script type="text/javascript" src="http://static.cnmo-img.com.cn/js/jquery144p.js"></script> <script> (function($) { /* ==================================================== 【JQuery插件】撲克翻牌效果 @auther LiuMing @blog http://www.cnblogs.com/dtdxrk/ ==================================================== @front:正面元素 @behind:背面元素 @direction:方向 @dis:距離 @mouse: 'enter' 'leave' 判斷鼠標移入移出 @speed: 速度 不填默認速度80 建議不要超過100 */ var OverTurnAnimate = function(front, behind, direction, dis, mouse, speed){ /*判斷移入移出*/ var $front = (mouse == 'enter') ? front : behind, $behind = (mouse == 'enter') ? behind : front; $front.stop(); $behind.stop(); if(direction == 'x'){ $front.animate({left: dis/2,width: 0},speed, function() { $front.hide(); $behind.show().animate({left: 0,width: dis},speed); }); }else{ $front.animate({top: dis/2,height: 0},speed, function() { $front.hide(); $behind.show().animate({top: 0,height: dis},speed); }); } }; /* @demo $('.demo1').OverTurn(@direction, @speed); @direction(String)必選 'y' || 'x' 方向 @speed(Number)可選 速度 */ $.fn.OverTurn = function(direction, speed) { /*配置參數(shù)*/ if(direction!='x' && direction!='y'){throw new Error('OverTurn arguments error');} $.each(this, function(){ var $this = $(this), $front = $this.find('.front'), $behind = $this.find('.behind'), dis = (direction=='x') ? $this.width() :$this.height(), s = Number(speed) || 80;/*默認速度80 建議不要超過100*/ $this.mouseenter(function() { OverTurnAnimate($front, $behind, direction, dis, 'enter', s); }).mouseleave(function() { OverTurnAnimate($front, $behind, direction, dis, 'leave', s); }); }); }; })(jQuery); /*插件引用方法y*/ $('.demo1').OverTurn('y',100);/*speed不填默認速度80 建議不要超過100*/ /*插件引用方法x*/ $('.demo2').OverTurn('x'); </script> </body> </html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
通過JQuery實現(xiàn)win8一樣酷炫的動態(tài)磁貼效果(示例代碼)
相信大家喜歡這個界面無非也是喜歡它的動態(tài)磁貼。剛好今天研究了一下如何通過JQuery在網(wǎng)頁上模仿這種效果,就貼出來給大家噴一下。雖然是一些很低級的技術(shù),但是也希望有需要的朋友可以參考下2013-07-07jquery實現(xiàn)未經(jīng)美化的簡潔TAB菜單效果
這篇文章主要介紹了jquery實現(xiàn)未經(jīng)美化的簡潔TAB菜單效果,涉及jquery鼠標click事件實現(xiàn)頁面元素樣式動態(tài)變換的功能,需要的朋友可以參考下2015-08-08textarea 在瀏覽器中固定大小和禁止拖動的實現(xiàn)方法
下面小編就為大家?guī)硪黄猼extarea 在瀏覽器中固定大小和禁止拖動的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,祝大家游戲愉快哦2016-12-12jquery的attr方法禁用表單元素禁用輸入內(nèi)容
這篇文章主要介紹了通過jquery的attr方法來禁用表單元素禁輸入內(nèi)容,示例如下,需要的朋友可以參考參考2014-06-06Jquery實時監(jiān)聽input value的實例
下面小編就為大家?guī)硪黄狫query實時監(jiān)聽input value的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01