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 相关文章推荐
JQuery Highcharts 动态生成图表的方法
Nov 15 Javascript
Jquery实现图片预加载与延时加载的方法
Dec 22 Javascript
node.js从数据库获取数据
May 08 Javascript
jqueryMobile 动态添加元素,展示刷新视图的实现方法
May 28 Javascript
微信小程序 页面之间传参实例详解
Jan 13 Javascript
Javascript同时声明一连串(多个)变量的方法
Jan 23 Javascript
JavaScript 中定义函数用 var foo = function () {} 和 function foo()区别介绍
Mar 01 Javascript
mpvue小程序仿qq左滑置顶删除组件
Aug 03 Javascript
浅谈angularJS2中的界面跳转方法
Aug 31 Javascript
Vue文件配置全局变量的实例
Sep 06 Javascript
详解JS取出两个数组中的不同或相同元素
Mar 20 Javascript
详解JavaScript的变量
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
PHP计划任务、定时执行任务的实现代码
2011/04/23 PHP
php命名空间学习详解
2014/02/27 PHP
PHP include任意文件或URL介绍
2014/04/29 PHP
php一个解析字符串排列数组的方法
2015/05/12 PHP
PHP 断点续传实例详解
2017/11/11 PHP
PHP var关键字相关原理及使用实例解析
2020/07/11 PHP
javascript中的对象和数组的应用技巧
2007/01/07 Javascript
基于jquery的页面划词搜索JS
2010/09/14 Javascript
判断JS对象是否拥有某种属性的两种方式
2013/12/02 Javascript
jQuery在页面加载时动态修改图片尺寸的方法
2015/03/20 Javascript
Spring mvc 接收json对象
2015/12/10 Javascript
举例讲解jQuery对DOM元素的向上遍历、向下遍历和水平遍历
2016/07/07 Javascript
jQuery+css实现非常漂亮的水平导航菜单效果
2016/07/27 Javascript
浅析Javascript ES6新增值比较函数Object.is
2016/08/24 Javascript
360提示[高危]使用存在漏洞的JQuery版本的解决方法
2017/10/27 jQuery
使用Angular CLI进行单元测试和E2E测试的方法
2018/03/24 Javascript
在Vue 中使用Typescript的示例代码
2018/09/10 Javascript
深入理解Vue keep-alive及实践总结
2019/08/21 Javascript
解决layer.confirm选择完之后消息框不消失的问题
2019/09/16 Javascript
小程序实现按下录音松开识别语音
2019/11/22 Javascript
Python+tkinter模拟“记住我”自动登录实例代码
2018/01/16 Python
用Python将结果保存为xlsx的方法
2019/01/28 Python
利用pandas将非数值数据转换成数值的方式
2019/12/18 Python
pytorch查看通道数 维数 尺寸大小方式
2020/05/26 Python
Pycharm学生免费专业版安装教程的方法步骤
2020/09/24 Python
Finishline官网:美国一家领先的运动品牌鞋类、服装零售商
2016/07/20 全球购物
利物浦足球俱乐部官方商店(美国):Liverpool FC US
2019/10/09 全球购物
应用化学专业职业生涯规划书
2013/12/31 职场文书
党的群众路线教育实践方案
2014/05/11 职场文书
学生无故旷课检讨书
2014/09/20 职场文书
试用期自我评价范文
2015/03/10 职场文书
2015年世界无烟日活动方案
2015/05/04 职场文书
2015秋学期开学寄语
2015/05/28 职场文书
毛主席纪念堂观后感
2015/06/17 职场文书
《夹竹桃》教学反思
2016/02/23 职场文书
go语言map与string的相互转换的实现
2021/04/07 Golang