jQuery实现扑克正反面翻牌效果
更新时间:2017年03月10日 15:13:52 作者:一者乎
本篇文章主要介绍了jQuery实现扑克正反面翻牌效果的实例。具有很好的参考价值。下面跟着小编一起来看下吧
效果图:

代码如下:
<!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) {
/*配置参数*/
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>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持脚本之家!
相关文章
jquery遍历之parent()和parents()的区别及parentsUntil()方法详解
这篇文章主要介绍了jquery遍历之parent()和parents()的区别及parentsUntil()方法。需要的朋友可以过来参考下,希望对大家有所帮助2013-12-12
jQuery-onload让第一次页面加载时图片是淡入方式显示
第一次打开一个页面时,让加载好的图片先隐藏,然后再执行动画fadeIn,这里的load事件:当所有子元素已经被完全加载完成时,load事件被发送到这个元素2012-05-05
基于jquery trigger函数无法触发a标签的两种解决方法
下面小编就为大家分享一篇基于jquery trigger函数无法触发a标签的两种解决方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-01-01
如何解决jQuery EasyUI 已打开Tab重新加载问题
最近在项目中遇到这样的需求,要求实现点击左侧已经打开的tab可以刷新重新加载datagrid。下面给大家分享实现代码,一起看看吧2016-12-12
模拟jQuery中的ready方法及实现按需加载css,js实例代码
这篇文章介绍了模拟jQuery中的ready方法及实现按需加载css,js实例代码,有需要的朋友可以参考一下2013-09-09
通过jquery.cookie.js实现记住用户名、密码登录功能
这篇文章主要介绍了通过jquery.cookie.js实现记住用户名、密码登录功能,通过Cookies让网站服务器把少量数据储存到客户端的硬盘或内存,从客户端的硬盘读取数据的一种技术;具体实现过程大家通过本文一起看看吧2018-06-06


最新评论