jQuery實(shí)現(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布局提示:背面默認(rèn)隱藏 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布局提示:背面默認(rèn)隱藏 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' 判斷鼠標(biāo)移入移出
@speed: 速度 不填默認(rèn)速度80 建議不要超過(guò)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;/*默認(rèn)速度80 建議不要超過(guò)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不填默認(rèn)速度80 建議不要超過(guò)100*/
/*插件引用方法x*/
$('.demo2').OverTurn('x');
</script>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
通過(guò)JQuery實(shí)現(xiàn)win8一樣酷炫的動(dòng)態(tài)磁貼效果(示例代碼)
相信大家喜歡這個(gè)界面無(wú)非也是喜歡它的動(dòng)態(tài)磁貼。剛好今天研究了一下如何通過(guò)JQuery在網(wǎng)頁(yè)上模仿這種效果,就貼出來(lái)給大家噴一下。雖然是一些很低級(jí)的技術(shù),但是也希望有需要的朋友可以參考下2013-07-07
jquery實(shí)現(xiàn)未經(jīng)美化的簡(jiǎn)潔TAB菜單效果
這篇文章主要介紹了jquery實(shí)現(xiàn)未經(jīng)美化的簡(jiǎn)潔TAB菜單效果,涉及jquery鼠標(biāo)click事件實(shí)現(xiàn)頁(yè)面元素樣式動(dòng)態(tài)變換的功能,需要的朋友可以參考下2015-08-08
jquery實(shí)現(xiàn)簡(jiǎn)單易懂的圖片展示小例子
圖片展示想必大家都見(jiàn)到過(guò)吧,下面有個(gè)不錯(cuò)的例子,通俗易懂,使用jquery實(shí)現(xiàn)的,感興趣的朋友不要錯(cuò)過(guò)2013-11-11
jQuery實(shí)現(xiàn)的簡(jiǎn)單百分比進(jìn)度條效果示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的簡(jiǎn)單百分比進(jìn)度條效果,結(jié)合簡(jiǎn)單實(shí)例形式分析了jQuery針對(duì)頁(yè)面元素的運(yùn)算與動(dòng)態(tài)操作相關(guān)操作技巧,需要的朋友可以參考下2016-08-08
textarea 在瀏覽器中固定大小和禁止拖動(dòng)的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇textarea 在瀏覽器中固定大小和禁止拖動(dòng)的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,祝大家游戲愉快哦2016-12-12
jquery的attr方法禁用表單元素禁用輸入內(nèi)容
這篇文章主要介紹了通過(guò)jquery的attr方法來(lái)禁用表單元素禁輸入內(nèi)容,示例如下,需要的朋友可以參考參考2014-06-06
Jquery實(shí)時(shí)監(jiān)聽(tīng)input value的實(shí)例
下面小編就為大家?guī)?lái)一篇Jquery實(shí)時(shí)監(jiān)聽(tīng)input value的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01

