纸牌翻牌游戏猜正反面C语言,jQuery实现扑克正反面翻牌效果

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

发布时间:2020-08-30 15:15:04

来源:脚本之家

阅读:79

作者:一者乎

效果图:

358d2ff7d52bf5f3efc89865040a7a90.png

代码如下:

【JQuery插件】扑克正反面翻牌效果

*{margin:0px;padding:0px;list-style:none;font-size: 16px;}

.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;}

demo1 y轴 (css布局提示:背面默认隐藏 height为0 top是高度的一半也就是demo中间)

正面正面正
面正面正面
背面
正面
背面

.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;}

demo2 x轴(css布局提示:背面默认隐藏 width为0 left是宽度的一半也就是demo中间)

正面
背面
正面
背面

(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');

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值