娃娃机项目框架html,移动端抓娃娃机

本文介绍了如何使用HTML、CSS和JavaScript实现手机抓娃娃游戏的基本原型,包括抓取时机控制、抓取概率设置以及视觉效果的动态调整。通过代码展示了移动元素的位置计算和动画变换,以及成功抓取和失败的随机事件处理。
摘要由CSDN通过智能技术生成

手机上的一个抓娃娃小游戏原型,有设定抓住的几率,这里就不做判断了,只实现抓取的效果!

971c3afe09a8

zww.png

HTML

JS

$(function(){

move = true;//移动

odds = true;//几率

var claw = $('.claw');

var clawH = claw.find('.a');

var claw_a = claw.find('.a').height();

var claw_b = claw.find('.b').height();

var obj = $('.prize');

obj.bind('touchstart',function(){

var _this = $(this);

if(move){

var p_t = _this.offset().top;

var p_l = _this.offset().left;

var c_l = claw.offset().left;

var moveX = p_l - c_l;

var moveY = p_t - claw_b;

var num = obj.index(this);//当前选择的奖品

console.log(p_t,p_l,c_l);

//console.log(num);

if(num !== 1 && num !== 4){//排除中间2个

claw.css({"-webkit-transform":"translate3d(" + moveX + "px,0,0)"});

setTimeout(function(){

clawH.css({height:moveY + "px"});

setTimeout(function(){

clawH.css({height:claw_a + "px"});

},500)

},300)

oddsEvent(800);

}else{

clawH.css({height:moveY + "px"});

setTimeout(function(){

clawH.css({height:claw_a + "px"});

},500)

oddsEvent(500);

}

}

move = false;//只抓一次

function oddsEvent(time){//抓取成功失败事件

if(odds){

console.log('抓到啦!o(∩_∩)o 哈哈')

setTimeout(function(){

_this.css({"-webkit-transform":"translate3d(0,-" + (moveY-claw_a) + "px,0)"});

},time)

}else{

console.log('没抓到(┬_┬)')

}

}

})

})

CSS

body{background: #2a2a2a;}

.prize_box {position: relative;margin-top:6rem;}

.prize_box ul {display: table;width: 100%;margin-top: 2rem;}

.prize_box ul li {display: table-cell;width: 33%;vertical-align:middle;}

.prize {width: 1.2rem;height: 1.2rem;background: #f80;margin: 0 auto;

transition:all .5s ease-out;

-webkit-transition:all .5s ease-out;

}

.claw {width: 1.2rem;position: absolute;z-index:10;top:0;left:50%;margin-left:-0.6rem;

transition:all .3s ease-out;

-webkit-transition:all .3s ease-out;

}

.claw .a {width: 0.2rem;height:0.8rem;background: #5349ab;margin: 0 auto;

transition:height .5s ease-out;

-webkit-transition:height .5s ease-out;

}

.claw .b {width: 1.2rem;height:1.2rem;background: #5349ab;}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值