特效描述:jQuery抽奖 砸金蛋代码。请在PHP环境下砸蛋
代码结构
1. 引入JS
2. HTML代码
锤子
1 2 3function eggClick(obj) {
var _this = obj;
$.getJSON("data.php",function(res){
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();
$('.resultTip').css({display:'block',top:'100px',left:_this.position().left+45,opacity:0}).animate({top: '50px',opacity:1},300,function(){
if(res.msg==1){
$("#result").html("恭喜,您中得"+res.prize+"!");
}else{
$("#result").html("很遗憾,您没能中奖!");
}
});
}
);
});
}
$(".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);
})