博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用html+css+js做打地鼠小游戏
阅读量:4619 次
发布时间:2019-06-09

本文共 2388 字,大约阅读时间需要 7 分钟。

代码连接  网盘共享:https://pan.baidu.com/s/1eSxocMm

html 代码 first.html

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>打地鼠</title> <link rel="stylesheet" href="first.css"> </head> <body> <section> </section> <!-- 添加积分器 --> <span id="count">得分 为0</span> <!-- 添加音频 hidden="true" --> <audio src="audio/music.mp3" loop="true"autoplay="autoplay" loop="loop"></audio> <div id="dazhong"></div> <script src="jquery.js"></script> <script src="first.js"></script> </body> </html>

 

 
 
 
 

css代码 first.css

html{
height: 100%;}body{
height: 100%; background-image: url('./image/bg.jpg'); display: flex; justify-content: center; /* align-items: center; */ position: relative;}section{
width: 760px; height: 400px; margin-top: 100px;}section div{
width: 160px; height: 140px; display: inline-block; margin-right: 30px; position: relative;}.hole{
display: inline-block; width:160px; position: absolute; bottom: 0; z-index: 1;}.mouse{
width:100px; z-index: 10; position: absolute; bottom:25px; left: 30px;}#count{
display:block; width:110px; height: 40px; font-size: 20px; font-weight: bold; text-align: center; line-height: 40px; background-color:brown; color: white; position: absolute; top:200px; left: 10px;}

 

 

js代码 first.js

 

for(var i=1;i<17;i++){ $('section').append('
'); }$('section div').append("");$('section div').append('');// 设置初始状态地鼠都没出现 $('.mouse').hide();//袋鼠出现 // [1,4] [0, 3)// 随机出现的袋鼠数目 [1 16] (0, 15] 向上取整var num// //袋鼠位置[0 15] 索引 index var index var object;setInterval(function(){ num=Math.ceil(Math.random()*2); for(var i=1; i<=num ;i++){ //随机出现的袋鼠位置[0 15] 索引 index=Math.floor(Math.random()*16); object=$('section div:nth-of-type('+(index+1)+') .mouse') object.slideDown(); object.delay(2000).slideUp(); } },1000);//鼠标锤子 图形$('.mouse').hover(function(){ $(this).css({ cursor:'url("./image/cursor-down.png"), auto' });},function(){ $('body').css({ cursor:'url("./image/cursor.png") ,auto' });});// score 记录敲到地鼠的分数var score=0;$('.mouse').click(function(){ score+=10; $(this).hide('fast'); $(" 得分 为"+score+"").replaceAll('span'); $('#dazhong').append('
'); setTimeout(function(){ $('#dazhong').empty(); },1000);});

 

转载于:https://www.cnblogs.com/shaoxiaohuan/p/7574172.html

你可能感兴趣的文章
黑马乐优商城
查看>>
synchronized用法
查看>>
Web前端开发规范
查看>>
Android Volley入门到精通:初识Volley的基本用法
查看>>
python中字符串拆分与合并——split()、join()、strip()和replace()
查看>>
14.Longest Common Prefix
查看>>
变量定义了 但是没有赋值的情况下 也会是undifine var n; alert(typeof(n))
查看>>
鼠标移动在屏幕上显示温度Tip提示功能-CToolTipCtrl类的使用
查看>>
[转]c#截取指定长度的字符串
查看>>
Android重启应用程序代码
查看>>
[老欧的问题]如何通过有ID的view找到其下没有ID的view
查看>>
java线程启动原理分析
查看>>
android中侧滑菜单的思路详解与实现
查看>>
内存泄露 的可能原因分析!
查看>>
Delphi 7下最小化到系统托盘
查看>>
Bzoj 1936
查看>>
限定符
查看>>
x250装无线网卡驱动ubuntu
查看>>
2017/11/9 Leetcode 日记
查看>>
第五周作业
查看>>