jQuery实现扑克正反面翻牌效果


Posted in Javascript onMarch 10, 2017

效果图:

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>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持三水点靠木!

Javascript 相关文章推荐
Javascript下IE与Firefox下的差异兼容写法总结
Jun 18 Javascript
javascript中数组中求最大值示例代码
Dec 18 Javascript
jQuery中常用的遍历函数用法实例总结
Sep 01 Javascript
js带前后翻页的图片切换效果代码分享
Sep 08 Javascript
JS中改变this指向的方法(call和apply、bind)
Mar 26 Javascript
Markdown+Bootstrap图片自适应属性详解
May 21 Javascript
详细讲解JavaScript中的this绑定
Oct 10 Javascript
关于RequireJS的简单介绍即使用方法
Oct 20 Javascript
canvas学习之API整理笔记(二)
Dec 29 Javascript
微信小程序 判断手机号的实现代码
Apr 19 Javascript
微信小程序网络请求wx.request详解及实例
May 18 Javascript
解决node终端下运行js文件不支持ES6语法
Apr 04 Javascript
AngularJS之页面跳转Route实例代码
Mar 10 #Javascript
Angular多选、全选、批量选择操作实例代码
Mar 10 #Javascript
jQuery插件HighCharts绘制2D带有Legend的饼图效果示例【附demo源码下载】
Mar 10 #Javascript
Vue.js之slot深度复制详解
Mar 10 #Javascript
JS实现的自动打字效果示例
Mar 10 #Javascript
jquery实现的table排序功能示例
Mar 10 #Javascript
微信小程序 向左滑动删除功能的实现
Mar 10 #Javascript
You might like
第三节 定义一个类 [3]
2006/10/09 PHP
新浪新闻小偷
2006/10/09 PHP
Windows下PHP的任意文件执行漏洞
2006/10/09 PHP
PHP 第二节 数据类型之转换
2012/04/28 PHP
php中base_convert()进制数字转换函数实例
2014/11/20 PHP
PHP使用GETDATE获取当前日期时间作为一个关联数组的方法
2015/03/19 PHP
php实现异步数据调用的方法
2015/12/24 PHP
nodeType属性返回被选节点的节点类型介绍
2013/11/22 Javascript
jQuery截取指定长度字符串代码
2014/08/21 Javascript
让JavaScript的Alert弹出框失效的方法禁止弹出警告框
2014/09/03 Javascript
浅谈javascript回调函数
2014/12/07 Javascript
javascript函数式编程程序员的工具集
2015/10/11 Javascript
JS获取时间的相关函数及时间戳与时间日期之间的转换
2016/02/04 Javascript
js简单实现图片延迟加载的方法
2016/07/19 Javascript
jQuery实用小技巧_输入框文字获取和失去焦点的简单实例
2016/08/25 Javascript
JS重载实现方法分析
2016/12/16 Javascript
js 输入框 正则表达式(菜鸟必看教程)
2017/02/19 Javascript
微信小程序 聊天室简单实现
2017/04/19 Javascript
js每隔两秒输出数组中的一项(实例)
2017/05/28 Javascript
JavaScript实现图片无缝滚动效果
2017/07/07 Javascript
JavaScript事件处理程序详解
2017/09/19 Javascript
详解jQuery中的getAll()和cleanData()
2019/04/15 jQuery
浅谈JS中this在各个场景下的指向
2019/08/14 Javascript
JavaScript Array对象使用方法解析
2019/09/24 Javascript
JavaScript实现网页跨年倒计时
2020/12/02 Javascript
[01:17:55]VGJ.T vs Mineski 2018国际邀请赛小组赛BO2 第一场 8.18
2018/08/20 DOTA
Python中的map、reduce和filter浅析
2014/04/26 Python
Python过滤列表用法实例分析
2016/04/29 Python
django重新生成数据库中的某张表方法
2019/08/28 Python
浅析PEP570新语法: 只接受位置参数
2019/10/15 Python
Python爬虫基于lxml解决数据编码乱码问题
2020/07/31 Python
万宝龙英国官网:Montblanc手表、书写工具、皮革和珠宝
2018/10/16 全球购物
2014年幼儿园国庆主题活动方案
2014/09/16 职场文书
党员个人自我评价
2015/03/03 职场文书
上帝也疯狂观后感
2015/06/09 职场文书
诚信教育主题班会
2015/08/13 职场文书