zjd

功能描述

欢乐砸金蛋

依赖的插件

jquery

快速使用

$(".eggbtn").click(function() {
    eggClick($(this));
});

function eggClick(obj) {
    var _this = $(".eggbtn");
    if(_this.hasClass("curr")){
        if(confirm("蛋都碎了,别砸了!刷新再来.")){
            window.location=window.location;	
        }
        return;
    }

$(".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"); //蛋碎效果
        $(".hammer").hide();
        $("#result").empty();
        $('.resultTip').css({display:'block',top:'50px',left:_this.position().left+80,opacity:0}).animate({top: '10px',opacity:1},300,function(){
                // 获取随机数
                var rand = rnd(1,7);
                // 根据随机数显示奖项,可用 ajax 返回值控制奖项
                zhaung(rand);
                var chance = parseInt($('#chance').html());
                chance = chance - 1;
                if(chance<0){
                    chance = 0;
                } 
                $('#chance').html(chance);
        });	
    }
);
}

//随机数
function rnd(n, m){
    return Math.floor(Math.random()*(m-n+1)+n)
}
// 奖项
function zhaung(nums){
    var shu = parseInt(nums)
    switch (shu) {
        case 1:
            $("#result").html("一等奖!");
            break;
        case 2:
            $("#result").html("二等奖!");
            break;
        case 3:
            $("#result").html("三等奖!");
            break;
        case 4:
            $("#result").html("四等奖!");
            break;
        case 5:
            $("#result").html("五等奖!");
            break;
        case 6:
            $("#result").html("安慰奖!");
            break;
        case 7:
            $("#result").html("未中奖!");
            break;
    }
}

是否仍需要帮助? 请保持联络!
最后更新于 2024/04/24