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 建議不要超過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 建議不要超過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 建議不要超過100*/
/*插件引用方法x*/
$('.demo2').OverTurn('x');
</script>
</body>
</html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
jquery遍歷之parent()和parents()的區(qū)別及parentsUntil()方法詳解
這篇文章主要介紹了jquery遍歷之parent()和parents()的區(qū)別及parentsUntil()方法。需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12
jQuery-onload讓第一次頁面加載時圖片是淡入方式顯示
第一次打開一個頁面時,讓加載好的圖片先隱藏,然后再執(zhí)行動畫fadeIn,這里的load事件:當(dāng)所有子元素已經(jīng)被完全加載完成時,load事件被發(fā)送到這個元素2012-05-05
基于jquery trigger函數(shù)無法觸發(fā)a標(biāo)簽的兩種解決方法
下面小編就為大家分享一篇基于jquery trigger函數(shù)無法觸發(fā)a標(biāo)簽的兩種解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
如何解決jQuery EasyUI 已打開Tab重新加載問題
最近在項(xiàng)目中遇到這樣的需求,要求實(shí)現(xiàn)點(diǎn)擊左側(cè)已經(jīng)打開的tab可以刷新重新加載datagrid。下面給大家分享實(shí)現(xiàn)代碼,一起看看吧2016-12-12
jquery結(jié)合css實(shí)現(xiàn)返回頂部功能
在本篇文章里小編給大家整理了一篇關(guān)于jquery結(jié)合css實(shí)現(xiàn)返回頂部功能的相關(guān)文章,有興趣的朋友們可以實(shí)例測試下。2021-08-08
基于EasyUI的基礎(chǔ)之上實(shí)現(xiàn)樹形功能菜單
這篇文章主要介紹了基于EasyUI的基礎(chǔ)之上實(shí)現(xiàn)樹形功能菜單,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-06-06
模擬jQuery中的ready方法及實(shí)現(xiàn)按需加載css,js實(shí)例代碼
這篇文章介紹了模擬jQuery中的ready方法及實(shí)現(xiàn)按需加載css,js實(shí)例代碼,有需要的朋友可以參考一下2013-09-09
通過jquery.cookie.js實(shí)現(xiàn)記住用戶名、密碼登錄功能
這篇文章主要介紹了通過jquery.cookie.js實(shí)現(xiàn)記住用戶名、密碼登錄功能,通過Cookies讓網(wǎng)站服務(wù)器把少量數(shù)據(jù)儲存到客戶端的硬盤或內(nèi)存,從客戶端的硬盤讀取數(shù)據(jù)的一種技術(shù);具體實(shí)現(xiàn)過程大家通過本文一起看看吧2018-06-06

