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处理json对象
Nov 03 Javascript
JQuery中使用on方法绑定hover事件实例
Dec 09 Javascript
jQuery Validate表单验证深入学习
Dec 18 Javascript
JavaScript对象参数的引用传递
Jan 14 Javascript
JavaScript队列、优先队列与循环队列
Nov 14 Javascript
使用vue.js编写蓝色拼图小游戏
Mar 17 Javascript
Vue.js基础学习之class与样式绑定
Mar 20 Javascript
浅谈SpringMVC中post checkbox 多选框value的值(隐藏域方式)
Jan 08 Javascript
Vue拖拽组件列表实现动态页面配置功能
Jun 17 Javascript
vue引入微信sdk 实现分享朋友圈获取地理位置功能
Jul 04 Javascript
javascript如何实现create方法
Nov 04 Javascript
vue-cli3.0修改打包后的文件名和文件地址,打包后本地运行报错解决
Apr 06 Vue.js
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
eaglephp使用微信api接口开发微信框架
2014/01/09 PHP
PHP将字符分解为多个字符串的方法
2014/11/22 PHP
php调用KyotoTycoon简单实例
2015/04/02 PHP
PHP设计模式之装饰者模式代码实例
2015/05/11 PHP
深入php内核之php in array
2015/11/10 PHP
php简单读取.vcf格式文件的方法示例
2017/09/02 PHP
语义化 H1 标签
2008/01/14 Javascript
使用jquery mobile做幻灯播放效果实现步骤
2013/01/04 Javascript
使用jQuery fancybox插件打造一个实用的数据传输模态弹出窗体
2013/01/15 Javascript
Javascript实现通过选择周数显示开始日和结束日的实现代码
2016/05/30 Javascript
JavaScript中 ES6 generator数据类型详解
2016/08/11 Javascript
javascript实现将数字转成千分位的方法小结【5种方式】
2016/12/11 Javascript
js实现表格筛选功能
2017/01/18 Javascript
TableSort.js表格排序插件使用方法详解
2017/02/10 Javascript
微信小程序movable view移动图片和双指缩放实例代码
2017/08/08 Javascript
详解vue中axios的封装
2018/07/18 Javascript
微信小程序开发注意指南和优化实践(小结)
2019/06/21 Javascript
基于原生js实现九宫格算法代码实例
2020/07/03 Javascript
解决vue 使用axios.all()方法发起多个请求控制台报错的问题
2020/11/09 Javascript
python实现定时播放mp3
2015/03/29 Python
Python修改MP3文件的方法
2015/06/15 Python
Python实现二叉树结构与进行二叉树遍历的方法详解
2016/05/24 Python
python daemon守护进程实现
2016/08/27 Python
Python与人工神经网络:使用神经网络识别手写图像介绍
2017/12/19 Python
scrapy spider的几种爬取方式实例代码
2018/01/25 Python
python使用PyQt5的简单方法
2019/02/27 Python
pow在python中的含义及用法
2019/07/11 Python
对Django中static(静态)文件详解以及{% static %}标签的使用方法
2019/07/28 Python
pandas数据拼接的实现示例
2020/04/16 Python
python实现canny边缘检测
2020/09/14 Python
英文商务邀请信
2014/01/22 职场文书
汽车销售员如何做职业生涯规划
2014/02/16 职场文书
个人工作总结范文2014
2014/11/07 职场文书
治理商业贿赂工作总结
2015/08/10 职场文书
红领巾广播站广播稿
2015/08/19 职场文书
高中数学课堂教学反思
2016/02/18 职场文书