`
wpf814533631
  • 浏览: 192064 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

简单的web页面计时器

阅读更多

这是页面内容

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无法屏蔽的网页右下角浮动窗口</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<SCRIPT src= "time.js"> </SCRIPT>
<style type="text/css">
#msg_win{border:1px solid #00ff00;width:180px;position:absolute;right:0;font-size:12px;font-family:Arial;margin:0px;display:none;overflow:hidden;z-index:99;}
#msg_win .icos{position:absolute;top:2px;*top:0px;right:2px;z-index:9;}
.icos a{float:left;color:#fff;margin:1px;text-align:center;font-weight:bold;width:14px;height:22px;line-height:22px;padding:1px;text-decoration:none;font-family:webdings;}
.icos a:hover{color:#fff;}
#msg_title{background:#336699;border-bottom:1px solid #fff;color:#ffcc00;height:25px;line-height:22px;font-weight:600;}
#msg_content{margin-right:0;width:180px;height:104px;overflow:hidden;background:#336699;}
.style_1{padding-left:6px;font-size:13px;font-family:'微软雅黑';color:#fff;height:20px;}
.style_2{font-size:12px;font-family:'微软雅黑';height:22px;text-align:center;background:#333333;color:#00ff00;border:#00ff00 solid 1px;}
.style_3{font-size:12px;font-family:'微软雅黑';height:22px;width:46px;}
</style>
</head>
<body onLoad="startclock(100);">
<p style="height:1000px;">这里是页面具体内容</p>
<div id="msg_win" style="display:block;top:490px;visibility:visible;opacity:1;">
<div class="icos"><a id="msg_min" title="最小化" href="javascript:void 0">_</a></div>
<div id="msg_title" style=""><font style="padding-left:5px;line-height:25px;vertical-align:super;">考试计时器</font></div>
<div id="msg_content">
	<form action="" name="clock">
		<table>
			<tr><td class="style_1">开始时间:</td><td><input class="style_2" name="start" size=13 disabled="disabled"></td></tr>
			<tr><td class="style_1">结束时间:</td><td><input class="style_2" name="end" size=13 disabled="disabled"></td></tr>
			<tr><td class="style_1">剩余时间:</td><td><input class="style_2" name="timer" size=13 disabled="disabled"></td></tr>
		</table>
		<div align="center" style="border-top:1px solid #fff;height:24px;">
			<input class="style_3" type="button" value="按钮">
			<input class="style_3" type="button" value="按钮">
			<input class="style_3" type="button" value="按钮">
		</div>
	</form>
</div>
</div>
</body>
</html>

以下是time.js内容

var Message={
	set: function() {//最小化与恢复状态切换
		var set=this.minbtn.status == 1?[0,1,'block',this.char[0],'最小化']:[1,0,'none',this.char[1],'恢复'];
		this.minbtn.status=set[0];
		this.win.style.borderBottomWidth=set[1];
		this.content.style.display =set[2];
		this.minbtn.innerHTML =set[3]
		this.minbtn.title = set[4];
		this.win.style.top = this.getY().top;
	},
	setOpacity: function(x) {//设置透明度
		var v = x >= 100 ? '': 'Alpha(opacity=' + x + ')';
		this.win.style.visibility = x<=0?'hidden':'visible';//IE有绝对或相对定位内容不随父透明度变化的bug
		this.win.style.filter = v;
		this.win.style.opacity = x / 100;
	},
	show: function() {//渐显
		clearInterval(this.timer2);
		var me = this,fx = this.fx(0, 100, 0.1),t = 0;
		this.timer2 = setInterval(function() {
		t = fx();
		me.setOpacity(t[0]);
		if (t[1] == 0) {clearInterval(me.timer2) }
		},10);
		},
		fx: function(a, b, c) {//缓冲计算
		var cMath = Math[(a - b) > 0 ? "floor": "ceil"],c = c || 0.1;
		return function() {return [a += cMath((b - a) * c), a - b]}
	},
	getY: function() {//计算移动坐标
		var d = document,b = document.body, e = document.documentElement;
		var s = Math.max(b.scrollTop, e.scrollTop);
		var h = /BackCompat/i.test(document.compatMode)?b.clientHeight:e.clientHeight;
		var h2 = this.win.offsetHeight;
		return {foot: s + h + h2 + 2+'px',top: s + h - h2 - 2+'px'}
	},
	moveTo: function(y) {//移动动画
		clearInterval(this.timer);
		var me = this,a = parseInt(this.win.style.top)||0;
		var fx = this.fx(a, parseInt(y));
		var t = 0 ;
		this.timer = setInterval(function() {
		t = fx();
		me.win.style.top = t[0]+'px';
		if (t[1] == 0) {
		clearInterval(me.timer);
		me.bind();
		}
		},10);
	},
	bind:function (){//绑定窗口滚动条与大小变化事件
		var me=this,st,rt;
		window.onscroll = function() {
		clearTimeout(st);
		clearTimeout(me.timer2);
		me.setOpacity(0);
		st = setTimeout(function() {
		me.win.style.top = me.getY().top;
		me.show();
		},600);
		};
		window.onresize = function (){
		clearTimeout(rt);
		rt = setTimeout(function() {me.win.style.top = me.getY().top},100);
		}
	},
	init: function() {//创建HTML
		function $(id) {return document.getElementById(id)};
		this.win=$('msg_win');
		var set={minbtn: 'msg_min',title: 'msg_title',content: 'msg_content'};
		for (var Id in set) {this[Id] = $(set[Id])};
		var me = this;
		this.minbtn.onclick = function() {me.set();this.blur()};
		this.char=navigator.userAgent.toLowerCase().indexOf('firefox')+1?['_','::','×']:['0','2','r'];//FF不支持webdings字体
		this.minbtn.innerHTML=this.char[0];
		setTimeout(function() {//初始化最先位置
		me.win.style.display = 'block';
		me.win.style.top = me.getY().foot;
		me.moveTo(me.getY().top);
		},0);
		return this;
	}
};

var timerID = null; 
var timerRunning = false;
var time = 0;
function stopclock(){ 
	if(timerRunning) 
		clearTimeout(timerID); 
	timerRunning = false;
} 
function startclock(total){ 
	Message.init();
	stopclock(); 
	showtime(total);
	time = total * 60;
	showsLast(); 
} 
function showtime(total){
	var now = new Date(); 
	var hours = now.getHours(); 
	var minutes = now.getMinutes(); 
	var seconds = now.getSeconds();
	var timeValue = "";
	timeValue += ((hours < 10) ? "0" : "") + hours; 
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes; 
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
	document.clock.start.value = timeValue;
	hours += Math.floor(total/60);
	minutes += Math.floor(total%60);
	if(minutes >60){
		hours += 1;
		minutes -=60;
	}
	timeValue = "";
	timeValue += ((hours < 10) ? "0" : "") + hours; 
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes; 
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
	document.clock.end.value = timeValue; 
}
function showsLast() {   
	var hours = Math.floor(time/3600); 
	var minutes = Math.floor(time/60-60); 
	var seconds = Math.floor(time%60);        
	timeValue = "";
	timeValue += ((hours < 10) ? "0" : "") + hours; 
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes; 
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
	document.clock.timer.value = timeValue;
	time = time - 1;   
	timerID = setTimeout("showsLast()",1000);
	timerRunning = true;     
}
 


只要将上述两个文件的内容放在同一根目录下即可。 

 

分享到:
评论

相关推荐

    立秋倒计时指定时间内多次调用.html

    js的一个简单应用,立秋倒...清除计时器 (==与使用的计时器一 一 对应==) clearInterVal(计时器名称) claerTimeOut( 计时器名称) 以上四个函数使用时都要说明计时器名称,否则可能出现第一次以后停止倒计时没有效果

    react-coming:React组件使用倒数计时器渲染一个简单的页面

    React来React组件使用倒数计时器呈现一个简单的页面。预览动机有时,当我们在网站或Web应用程序上工作时,我们希望尽快进行部署并向用户展示某些内容。 react-coming库使您可以使用未来的日期倒计时快速呈现视图。 ...

    Web定时器「Web Timer」-crx插件

    - 轻松地与朋友分享您的Web计时器统计信息 说明: - 使用选项页面来避免跟踪某些网站 注意:我最初出售扩展名(https://chrome.google.com/webstore/detail/web-timer/ggnjbdfgigejghknieofeahaknkjafim?hl=en),...

    Pomodorino:Pomodorino是一款轻巧的Pomodoro计时器,强调简单性和功能性

    Pomodorino是一个Pomodoro计时器,强调简单性和功能性。 计时器基于Francesco Cirillo创建。 它的名字来自意大利语,意为小番茄,因为它是当今网络上可安装版本的轻量级版本。 如果您想 ,则该应用程序托管在GitHub...

    课程设计JavaWeb大作业web电脑考试系统项目源码+数据库.zip

    课程设计JavaWeb大作业web电脑考试系统项目源码和数据库,内含详细使用说明,项目文档,初学者的福音啊(捂脸)高手可以二次开发 项目特色 1. 精美炫酷的登录页面 2. 设计合理,左侧式导航栏,顶部二级菜单 3. 32位 ...

    二十五:TwentyFive是一个HTML5时间跟踪Web应用程序,专注于速度和简便性,鼓励您遵循Pomodoro技术

    基于Date的计时器,而不是基于不可靠的JS计时器的计时器() 响应式设计 永久计时器(您可以关闭窗口,它将继续计数) 在实时试用 作者 由设计和开发。 学分 该UI受Juani的启发很大(尽管它已经从头开始进

    ASP.NET AJAX实战源码

    4.4.4 使用计时器 101 4.4.5 错误处理 103 4.5 小结 104 第5章 建立异步网络调用 105 5.1 使用ASP.NET Web服务 105 5.1.1 配置Web服务 106 5.1.2 从JavaScript调用Web服务方法 109 5.1.3 处理复杂类型 111 ...

    pomoReward:供我个人使用的最小番茄计时器

    最小番茄钟 一个用纯...自定义计时器声音 更好的设计 添加本地存储 添加关于/维基页面 中断模式* 仪表板* 奖励的东西* 设定页面 添加更多主题 这是处于Beta阶段,因此某些内容仍然不完整,但仍足以使用。

    Next Tab-crx插件

    您可以使用它在计时器用尽后强制移至下一个打开的选项卡,甚至关闭选项卡。 在安装后,通过右键单击扩展按钮并选择“选项”菜单,可以在选项菜单中激活这些功能以及更多功能。 有关更多信息,请访问sicutunum....

    jmeter-aem-templates:AEM JMeter模板是预定义的AEM Web应用程序测试计划模板,可以立即使用

    使用参数化的高斯随机计时器思考时间, 具有针对不同测试环境的用户定义变量的测试配置文件, HTTP请求配置为下载嵌入式资源,并行下载和过滤出对第三方域的调用, 示例性的HTTP请求(GET,POST)和配

    使用JavaScript实现网页秒表功能(含开始、暂停、继续、重置功能)

    效果图展示,感觉不错可以参考实例代码。 具体代码如下所示: &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt;...meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;...button disabled

    countdown-timer:半永久的に计れるカウントダウンタイマーです

    倒计时器半永久的に计れるタイマー这是一个可以半永久性计时的计时器。屏幕截图 月份和日期设置 时间设定如何使用使用非常简单。 设置闹钟响起的时间。 按下SET按钮。特征这个程序是闹钟和计时器的完美结合。 设置的...

    AADM-Freedom-Fund:UGA学生为A​​ADM Freedom Fund开发的Web抓取应用程序

    每天早上(在计时器上)从该收集可公开获取的数据 将抓取的数据处理到Python字典中,然后导入到SQL数据库我们将有两种模式:一种用于用户登录并存储抓取的数据 创建登录页面和主页 登录页面。-我们现在可以将其保持...

    rutorrent-pausewebui:使您能够在ruTorrent中暂停webui

    插件可暂停刷新计时器,并添加一个按钮以手动刷新页面。安装下载,解压缩并添加到rutorrent plugins目录。 也可以选择通过git安装。 假设您的rutorrent根目录为/var/www/rutorrent/发出以下命令: cd /var/...

    HTML5程序设计(第2版).[荷]Peter Lubbers(带详细书签).pdf

    2.3.2 进阶功能之为Canvas动画计时 54 2.4 小结 57 第3章 SVG 58 3.1 SVG概述 58 3.1.1 历史 58 3.1.2 理解SVG 59 3.1.3 可缩放图形 61 3.1.4 使用SVG创建2D图形 61 3.1.5 在页面中添加SVG 61 3.1.6 简单的...

    asimov-deploy:简单的分布式部署

    Asimov Deploy是一个简单的分布式部署工具,使您可以通过中央Web界面将应用程序部署到多台计算机。 实际的部署人员由本地安装的部署代理在每台计算机上进行处理。 您可以尝试一下:。 部署Web服务器/界面 跨平台...

    Code-Quiz:UW编码训练营的此项作业4

    单击“开始测验”按钮时,将向用户显示一系列问题,计时器具有一个值,并立即开始倒计时。 最终分数由剩余时间计算得出。 快速正确地回答将导致更高的分数。 但是错误回答会导致时间浪费。 当所有问题均已回答或...

    Code-Quiz

    04 Web API:代码测验 用户的故事 该应用程序是为训练营的学生创建的,可以在一定时间内测试他们对JavaScript基础的知识。 他们可以保存分数并将其分数与同龄人进行比较。... 单击开始测验按钮后,计时器开始计时

Global site tag (gtag.js) - Google Analytics