jQuery掷色子动画

jQuery掷色子动画

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>演示:jQuery掷色子动画</title>
<style type="text/css">
.demo{width:760px; height:120px; margin:10px auto;}
.wrap{width:90px; height:90px; margin:120px auto 30px auto; position:relative}
.dice{width:90px; height:90px; background:url(http://www.aspku.com/jscss/demoimg/201404/dice.png) no-repeat; cursor:pointer;}
.dice_1{background-position:-5px -4px}
.dice_2{background-position:-5px -107px}
.dice_3{background-position:-5px -212px}
.dice_4{background-position:-5px -317px}
.dice_5{background-position:-5px -427px}
.dice_6{background-position:-5px -535px}
.dice_t{background-position:-5px -651px}
.dice_s{background-position:-5px -763px}
.dice_e{background-position:-5px -876px}
p#result{text-align:center; font-size:16px}
p#result span{font-weight:bold; color:#f30; margin:6px}
#dice_mask{width:90px; height:90px; background:#fff; opacity:0; position:absolute; top:0; left:0; z-index:999}
</style>
<script type="text/javascript" src="http://www.aspku.com/ajaxjs/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function(){
	var dice = $("#dice");
	dice.click(function(){
		$(".wrap").append("<div id='dice_mask'></div>");//加遮罩
		dice.attr("class","dice");//清除上次动画后的点数
		dice.css('cursor','default');
		var num = Math.floor(Math.random()*6+1);//产生随机数1-6
		dice.animate({left: '+2px'}, 100,function(){
			dice.addClass("dice_t");
		}).delay(200).animate({top:'-2px'},100,function(){
			dice.removeClass("dice_t").addClass("dice_s");
		}).delay(200).animate({opacity: 'show'},600,function(){
			dice.removeClass("dice_s").addClass("dice_e");
		}).delay(100).animate({left:'-2px',top:'2px'},100,function(){
			dice.removeClass("dice_e").addClass("dice_"+num);
			$("#result").html("您掷得点数是<span>"+num+"</span>");
			dice.css('cursor','pointer');
			$("#dice_mask").remove();//移除遮罩
		});
	});
});
</script>
</head>
<body>
<div id="main">
   <h2 class="top_title">jQuery掷色子动画</h2>
   <div class="demo">
   		<div class="wrap">
   			<div id="dice" class="dice dice_1"></div>
        </div>
        <p id="result">请直接点击上面的色子!</p>
   </div>
</div>
</body>
</html>
阿强爱分享
  • 本文由 发表于 2019年10月24日04:11:01
  • 转载请务必保留本文链接:https://iooqp.cn/535.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: