当前位置: 首页 > article >正文

前端 :用HTML , CSS ,JS 做一个秒表

1.HTML:

<body>
        <div id = "content">
            <div id = "top">
                <div id="time">00:00:000</div>
            </div>
            <div id = "bottom">
                <div id = "btn_start">开始</div>
                <div id = "btn_stop">停止</div>
                <div id = "btn_reset">重置</div>
            </div>
        </div>
    </body>

2.CSS

<script src="jquery-3.6.0.js"></script>
		<style>
			*{
				margin: 0;
				padding: 0;
			}
			html,body{
				width: 100%;
				height: 100%;
			}
			#content{
				width: 100%;
				height: 100%;
				position: relative;
				background:url("img/1.cpp.jpg");
				background-size: 100% 100%;
			}
			#top{
				width:100%;
				height: 250px;
				position: relative;	
			}
			#time{
				font-size: 100px;
				background-color: gray;
				color: white;
				position: absolute;
				top: 50%;
				margin-top:-60px ;
				left: 50%;
				margin-left: -220px;
				border-radius: 20px;
			}
			#bottom{
				width:100%;
				height: 400px;
				position: relative;	
				top: 100px;
			}
			#btn_start{
				font-size: 50px;
				background-color: red;
				width: 20%;
				color: white;text-align: center;
				position: absolute;
				top: 20px;
				left: 40%;
				border-radius: 30px;
				}
			#btn_stop{
				font-size: 50px;
				background-color: orange;
				width: 20%;
				color: white;text-align: center;
				position: absolute;
				top: 150px;
				left: 40%;
				border-radius: 30px;
			}
			#btn_reset{
				font-size: 50px;
				background-color: greenyellow;
				width: 20%;
				color: white;text-align: center;
				position: absolute;
				top: 280px;
				left: 40%;
				border-radius: 30px;
			}
		</style>

3.JS

<script type="text/javascript">
	var min = 0;
	var m = 0;
	var ms = 0;
	var id = 0;
	function jsq(){
		if(ms==100)
		{
			ms=0;
			if(m==60){
				min++;
				m=0;
				if(min==60){
					min=0;
					clearInterval(id);
				}
				else{
					min++;
				}
			}
			else{
				
				m++;
			}
		}
		else{
			ms++;
		}
		$("#time").html(min+":"+m+":"+ms);
	}
	$("#btn_start").click(function(){
		id = setInterval(jsq,10);
		
	});
	$("#btn_stop").click(function(){
		clearInterval(id);
	});
	$("#btn_reset").click(function(){
		location.reload();
	});
</script>

效果展示:


http://www.kler.cn/news/109181.html

相关文章:

  • CN考研真题知识点二轮归纳(1)
  • 【Unity PlasticSCM】记录:从介绍 下载 到拉取项目
  • 让谷歌插件单独一个窗口运行
  • TSINGSEE青犀基于AI视频识别技术的平安校园安防视频监控方案
  • 无法查看 spring-boot-starter-parent的pom.xml
  • Linux命令(108)之dirname
  • Mybatis 动态SQL
  • Python mysql 封装备用
  • Go学习第十六章——Gin文件上传与下载
  • Vue路由
  • 基于单片机的温湿度和二氧化碳检测系统设计
  • TensorFlow图像多标签分类实例
  • 【鸿蒙软件开发】ArkTS基础组件之TextTimer(文本显示计时)、TimePicker(时间选择)
  • 校园物业报修小程序开发笔记一
  • C/C++晶晶赴约会 2020年12月电子学会青少年软件编程(C/C++)等级考试一级真题答案解析
  • 基于单片机的超声波探伤仪设计
  • 一句话解释什么是出口IP
  • 0基础学习VR全景平台篇第114篇:全景图优化和输出 - PTGui Pro教程
  • LuaTable转C#的列表List和字典Dictionary
  • Openssl数据安全传输平台015:OCCI的使用方法+在项目中的设计与实现
  • java中spi与api的区别
  • “破解我!“---160个CrackMe练习001-Acid buen.exe
  • 免费活动-11月4日敏捷武林上海站 | Scrum.org CEO 亲临现场
  • 深入理解Linux网络笔记(五):深度理解本机网络IO
  • 【技能树笔记】网络篇——练习题解析(十)
  • STM32-通用定时器
  • SpringBoot 整合 Nacos 实现统一配置中心
  • Azure云工作站上做Machine Learning模型开发 - 全流程演示
  • DVWA-SQL Injection SQL注入
  • 当『后设学习』碰上『工程学思维』