砸金蛋

<!DOCTYPE html>
<!-- saved from url=(0046)http://demo.jq22.com/jquery-eggs-150323222243/ -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="keywords" content="jquery,php,砸金蛋">
<meta name="description">
<title>砸金蛋</title>


<style type="text/css">
.egg{width:660px; height:400px; margin:50px auto 20px auto;}
.egg ul li{z-index:999;}
.eggList{padding-top:110px;position:relative;width:660px;}
.eggList li{float:left;background:url(images/egg_1.png) no-repeat bottom;width:158px;height:187px;cursor:pointer;position:relative;margin-left:35px; list-style:none}
.eggList li span{position:absolute; width:30px; height:60px; left:68px; top:64px; color:#ff0; font-size:42px; font-weight:bold}
.eggList li.curr{background:url(images/egg_2.png) no-repeat bottom;cursor:default;z-index:300; list-style:none}
.eggList li.curr sup{position:absolute;background:url(images/img-4.png) no-repeat;width:232px; height:181px;top:-36px;left:-34px;z-index:800; list-style:none}
.hammer{background:url(images/img-6.png) no-repeat;width:74px;height:87px;position:absolute; text-indent:-9999px;z-index:150;left:168px;top:100px;}
.resultTip{position:absolute; background:#ffc ;width:148px;padding:6px;z-index:500;top:200px; left:10px; color:#f60; text-align:center;overflow:hidden;display:none;z-index:500;}
.resultTip b{font-size:14px;line-height:24px;}
</style>
</head>


<body>
<div id="header">
  
</div>
<div id="main">
  
<div class="egg">
<ul class="eggList">
<p class="hammer" id="hammer" style="left: 391px; top: 85px; display: block;">锤子</p>
<p class="resultTip" id="resultTip" style="display: none; top: 50px; left: 85px; opacity: 1;"><b id="result" style="display: none;"></b></p>
<li class="curr"><span style="display: none;">1</span><sup></sup></li>
<li><span>2</span><sup></sup></li>
<li><span>3</span><sup></sup></li>
</ul>
</div>

</div>
<script type="text/javascript" src="./砸金蛋_files/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function eggClick(obj) {
var _this = obj;
if(_this.hasClass("curr")){
alert("蛋都碎了,别砸了!刷新再来.");
return false;
}
//_this.unbind('click');
$(".hammer").css({"top":_this.position().top-55,"left":_this.position().left+185});
$(".hammer").animate({
"top":_this.position().top-25,
"left":_this.position().left+125
},30,function(){
_this.addClass("curr"); //蛋碎效果
_this.find("sup").show(); //金花四溅
$(".hammer").hide();
$("#result").empty();
$("#result").hide();
$('.resultTip').css({display:'none',top:'100px',left:_this.position().left+45,opacity:0}).animate({top: '50px',opacity:1},300,function(){
//中奖状态
           var award = [["神仙姐姐",1],["如花",2],["芙蓉姐姐",3],["凤姐",4]];
           var num = 0;
           //几率求和
           for(var i=0;i<award.length;i++){
                    num+=award[i][1];
       }
       var r = 0;
       var award_k='';
       //概率
       for(var i=0;i<award.length;i++){
         r = randomNum(1,num);
         if(r<=award[i][1]){
         award_k=award[i];
         break;
      }else{
                      num-=award[i][1];
 }
   }
   alert(award_k[0]);
});
}
);

}
//指定范围的随机数
function randomNum(Min,Max){ 
 
    var Range = Max - Min; 


    var Rand = Math.random(); 


    return(Min + Math.round(Rand * Range)); 





$(".eggList li").click(function() {
$(this).children("span").hide();
eggClick($(this));
});


$(".eggList li").hover(function() {
var posL = $(this).position().left + $(this).width();
$("#hammer").show().css('left', posL);
})
</script>


<div id="footer">
</div>




</body></html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值