纯css写出来的一个Iphone

分享 :

预览:

源码:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/js.js"></script>
<title>打地鼠游戏案例</title>
<style type="text/css">
    @charset "utf-8";
/* CSS Document */
*{ margin:0px auto; padding:0px;}
.claer{ clear:both;}

.main{ width:500px;background:#c6c6c6; cursor:url(../img/111.ico),-moz-zoom-out; height:100%;}
.frame{ display:block; background:url(../img/keng.png) no-repeat ; float:left; margin:30px;  width:102px; height:58px;}
</style>
</head>

<body>
<div class="main">
	<span class="frame" id="frame1"></span>
    <span class="frame" id="frame2"></span>
    <span class="frame" id="frame3"></span>
    <span class="frame" id="frame4"></span>
    <span class="frame" id="frame5"></span>
    <span class="frame" id="frame6"></span>
    <span class="frame" id="frame7"></span>
    <span class="frame" id="frame8"></span>
    <span class="frame" id="frame9"></span>
    <div class="claer"></div>
</div>
<div>
	<span id="he">0</span>
    <span id="error">0</span>
</div>

</body>
<script type="text/javascript">
    // JavaScript Document
function dian(){
    
    for(i=1;i<10;i++){//循环取出每个id
        var bg = document.getElementById('frame'+i);
        bg.onclick = function(){//没有地鼠的id点击事件
            var cuowu = document.getElementById("error");
            cuowu.innerHTML++;//失败数值加1
            if(cuowu.innerHTML=="3"){//判断如果等于3
                cuowu.innerHTML="0"
                var zonghe = document.getElementById("he");
                alert("你失败了"+"你一共打了"+zonghe.innerHTML+"个地鼠");
                    clearTimeout(b);
                bg.style.background="url(img/keng.png)";    
                }
            }
        bg.style.background="url(img/keng.png)";
        }
var ran =parseInt(Math.random()*9,10)+1;//取1-9的随机数
    
    
    var bg = document.getElementById('frame'+ran);  
                bg.onclick=function(){//有地鼠的点击事件
            var zonghe = document.getElementById("he");
            bg.style.background="url(img/da.png)";
             zonghe.innerHTML++;
             if(zonghe.innerHTML=="100"){
                 alert("恭喜你,大神!!!");
                clearTimeout(b);
                //bg.style.background="url(img/keng.png)";
                 }
            }
    bg.style.background="url(img/dishu.gif)";
    

    
    }
    

//定时器
window.onload = function times(){   

 b = setInterval("dian()",800);//1000为1秒钟
}


</script>
</html>

文章分类

在线客服
热线电话

微信公众账号