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 相关文章推荐
DHTML 中的绝对定位
Nov 26 Javascript
JS定义回车事件(实现代码)
Jul 08 Javascript
简单js代码实现selece二级联动(推荐)
Feb 18 Javascript
js计算文本框输入的字符数
Oct 23 Javascript
JavaScript 数组some()和filter()的用法及区别
May 20 Javascript
实例讲解JavaScript中的this指向错误解决方法
Jun 13 Javascript
jquery插件autocomplete用法示例
Jul 01 Javascript
PhotoSwipe异步动态加载图片方法
Aug 25 Javascript
JS实现二叉查找树的建立以及一些遍历方法实现
Apr 17 Javascript
bootstrap响应式工具使用详解
Nov 29 Javascript
jQuery实现文本显示一段时间后隐藏的方法分析
Jun 20 jQuery
详解ES6实现类的私有变量的几种写法
Feb 10 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中的float类型使用说明
2010/07/27 PHP
discuz程序的PHP加密函数原理分析
2011/08/05 PHP
PHP中读取文件的8种方法和代码实例
2014/08/05 PHP
php禁止浏览器使用缓存页面的方法
2014/11/07 PHP
Laravel 5框架学习之用户认证
2015/04/09 PHP
PHP中array_keys和array_unique函数源码的分析
2016/02/26 PHP
实例讲解PHP表单验证功能
2019/02/15 PHP
Extjs学习笔记之一 初识Extjs之MessageBox
2010/01/07 Javascript
javascript实现俄罗斯方块游戏的思路和方法
2015/04/27 Javascript
用JS写的一个Ajax库(实例代码)
2016/08/06 Javascript
用nodejs的实现原理和搭建服务器(动态)
2016/08/10 NodeJs
Extjs让combobox写起来简洁又漂亮
2017/01/05 Javascript
Angular多选、全选、批量选择操作实例代码
2017/03/10 Javascript
jQuery tip提示插件(实例分享)
2017/04/28 jQuery
js中this的指向问题归纳总结
2018/11/28 Javascript
用WebStorm进行Angularjs 2开发(环境篇:Windows 10,Angular-cli方式)
2018/12/05 Javascript
Vue项目中使用jquery的简单方法
2019/05/16 jQuery
express框架下使用session的方法
2019/07/31 Javascript
Vue打包部署到Nginx时,css样式不生效的解决方式
2020/08/03 Javascript
Vue实现指令式动态追加小球动画组件的步骤
2020/12/18 Vue.js
vue实现验证用户名是否可用
2021/01/20 Vue.js
Python的批量远程管理和部署工具Fabric用法实例
2015/01/23 Python
用python记录运行pid,并在需要时kill掉它们的实例
2017/01/16 Python
Python编写一个闹钟功能
2017/07/11 Python
pyqt5 从本地选择图片 并显示在label上的实例
2019/06/13 Python
关于Pytorch MaxUnpool2d中size操作方式
2020/01/03 Python
浅谈matplotlib 绘制梯度下降求解过程
2020/07/12 Python
python实现excel公式格式化的示例代码
2020/12/23 Python
学期研究性学习个人的自我评价
2014/01/09 职场文书
电子商务专业求职信
2014/03/08 职场文书
伊索寓言教学反思
2014/05/01 职场文书
高中学生会竞选演讲稿
2014/08/25 职场文书
小学师德师风演讲稿
2014/09/02 职场文书
党员弘扬焦裕禄精神思想汇报
2014/09/10 职场文书
mysql优化
2021/04/06 MySQL
Python实现数据的序列化操作详解
2022/07/07 Python