南宁小程序开发,挑战百日学习计划第30天(flex布局-丢骰子)

【南宁小程序开发:www.zkelm.com】,学了CSS 之后 顺便接触了一些CSS3.0的语法,感觉css3.0更好玩。接下来准备画费有点时间去把CSS3.0撸一遍,看看到底是啥玩意 。

我设计是这样子的:1.点击骰子 自动滚动到另外一边, 然后随机出现点数
南宁小程序开发公司:zkelm.com
因为我用的是纯CSS写的, 所以想了两天,终于想到了好办法, 就是先布局7个点, 然后随机设置点的背景色=#DDD 这样子看起来。就是点数变化了, 而且还不影响骰子的排布变现。 hoho 真聪明!

好咧 废话不多说,直接附上代码 copy就可以直接运行,

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>flex制作骰子</title>

  <style>
   body{background: #000;}
   .box{
	position: relative;
    width:90px;
    height: 90px;
    border: 1ps solid #fff;
    background: #bbb;
    border-radius:10px;
    display: flex;
    flex-direction:center;
    justify-content: center;
    align-items:center;	
	
	
   }
   .flexcontainer{
	display: flex;
    width:80px;
    height: 80px;
    border:1px solid #ddd;
    border-radius: 8px;
    background: #ddd;
    box-shadow: 2px 2px 3px #888;
    flex-direction: column;
	flex-wrap:wrap;
	justify-content: space-between;
    
   }
   .flexitems{
    margin:3px;
    width:20px;
    height: 20px;
    background: #000;
    border-radius:50%;
   }
   .column{
   	  display: flex;
	  justify-content: space-between;
	  
   }
   .column:nth-child(2) {
	   justify-content: center;
	   
   }
   myhide{
	   background-color: #ddd;
   }
   myshow{
	   background-color: #f55;
   }
   @keyframes myfirst{
	   0%{left:0px;top:0px;transform:rotate(0deg)}
	   100%{left:400px;top:100px;transform:rotate(3600deg)}
   }
   .moveanimate{
	   animation:myfirst 5s;
   }
  </style>
 </head>
 <body><div class="box" onclick="Addstyle()" >
  <div class="flexcontainer">
	  <div class="column">
           <div id="1" class="flexitems"></div>
           <div id="2"  class="flexitems"></div>
			<div id="3"  class="flexitems"></div>
		   
	</div>
	<div class="column"><div id="4"class="flexitems"></div></div>
	<div class="column">
	        <div id="5" class="flexitems"></div>
	        <div id="6" class="flexitems"></div>
			<div id="7" class="flexitems"></div>
	 </div>
   </div>
  
  </div><br>
 

<script type="text/javascript">
	function Addstyle(){
		setTimeout(function(){
			var spot=Math.round(Math.random()*5)
			
			if(spot==0){
				document.getElementById("1").style.background="#DDDDDD"
				document.getElementById("2").style.background="#DDDDDD"
				document.getElementById("3").style.background="#DDDDDD"
				document.getElementById("4").style.background="#000"
				document.getElementById("5").style.background="#DDDDDD"
				document.getElementById("6").style.background="#DDDDDD"
				document.getElementById("7").style.background="#DDDDDD"
			}else if(spot==1){
				document.getElementById("1").style.background="#000"
				document.getElementById("2").style.background="#DDDDDD"
				document.getElementById("3").style.background="#DDDDDD"
				document.getElementById("4").style.background="#DDDDDD"
				document.getElementById("5").style.background="#DDDDDD"
				document.getElementById("6").style.background="#DDDDDD"
				document.getElementById("7").style.background="#000"
			}else if(spot==2){
				document.getElementById("1").style.background="#000"
				document.getElementById("2").style.background="#DDDDDD"
				document.getElementById("3").style.background="#DDDDDD"
				document.getElementById("4").style.background="#000"
				document.getElementById("5").style.background="#DDDDDD"
				document.getElementById("6").style.background="#DDDDDD"
				document.getElementById("7").style.background="#000"
				
			}else if(spot==3){
				document.getElementById("1").style.background="#000"
				document.getElementById("2").style.background="#DDDDDD"
				document.getElementById("3").style.background="#000"
				document.getElementById("4").style.background="#DDDDDD"
				document.getElementById("5").style.background="#000"
				document.getElementById("6").style.background="#DDDDDD"
				document.getElementById("7").style.background="#000"
			}else if(spot==4){
				document.getElementById("1").style.background="#000"
				document.getElementById("2").style.background="#DDDDDD"
				document.getElementById("3").style.background="#000"
				document.getElementById("4").style.background="#000"
				document.getElementById("5").style.background="#000"
				document.getElementById("6").style.background="#DDDDDD"
				document.getElementById("7").style.background="#000"
				
			}else{
				document.getElementById("1").style.background="#000"
				document.getElementById("2").style.background="#000"
				document.getElementById("3").style.background="#000"
				document.getElementById("4").style.background="#DDDDDD"
				document.getElementById("5").style.background="#000"
				document.getElementById("6").style.background="#000"
				document.getElementById("7").style.background="#000"
			}	
		},1500)
	    document.querySelector(".box").style.animation="myfirst 5s";
		setTimeout(function(){
			document.querySelector(".box").style.animation="";
			
		},5500)
		
	}
	
	
	window.onload=function(){
		document.getElementById("1").style.background="#DDDDDD"
		document.getElementById("2").style.background="#DDDDDD"
		document.getElementById("3").style.background="#DDDDDD"
		document.getElementById("5").style.background="#DDDDDD"
		document.getElementById("6").style.background="#DDDDDD"
		document.getElementById("7").style.background="#DDDDDD"
		
	}
	
</script>
 </body>
</html>

南宁小程序开发:zkelm.com

每天进步1% ,贵在坚持 . 我学到什么新技术我就在这里更新出来给大家参考,见证我学习的脚步.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值