<HTML>
<HEAD>
<STYLE TYPE='text/css'>
#myChaser {
position:absolute;
left:0px;
top:0px;
width:400px;
color:#555555;
font-family:宋体;
font-size:11pt;
}
</STYLE>
</HEAD><BODY>
<DIV ID='myChaser'></DIV>
<SCRIPT LANGUAGE='JavaScript'>var lefttime = 3600 //总时间function tim()
{
document.all.myChaser.innerHTML = "<b>剩余时间:<font color=red>" + lefttime + "</font>秒,你可以转换成时分秒的形式来显示</b>"
lefttime--
setTimeout("tim()",1000)
}
tim()var oChaser = {
topMargin : 0,
callRate : 1,
slideTime : 10,
maxDiff : document.all ? document.body.clientHeight : window.innerHeight,
isIE : document.all ? true : false,
chaserDiv : document[document.all ? "all" : "layers"]["myChaser"]
}window.setInterval("oChaser.main( )", oChaser.callRate)
oChaser.main = function( )
{
this.currentY = this.isIE ? this.chaserDiv.style.pixelTop : this.chaserDiv.top //pixelTop:该对象的top属性值,与top数值一样,但它是整型,不是字符型的值
this.scrollTop = this.isIE ? document.body.scrollTop : window.pageYOffset //scrollTop:顶部滚动过的距离
var newTargetY = this.scrollTop + this.topMarginif ( this.currentY != newTargetY ) { if ( newTargetY != this.targetY ) { this.targetY = newTargetY
this.slideInit( ) } this.slide( )
}
}oChaser.slideInit = function( )
{
var now = new Date( )this.A = this.targetY - this.currentY
this.B = Math.PI / ( 2 * this.slideTime )
this.C = now.getTime( )if (Math.abs(this.A) > this.maxDiff) {
this.D = this.A > 0 ? this.targetY - this.maxDiff : this.targetY + this.maxDiff
this.A = this.A > 0 ? this.maxDiff : -this.maxDiff
} else {
this.D = this.currentY
}
}oChaser.slide = function( )
{
var now = new Date( )
var newY = this.A * Math.sin( this.B * ( now.getTime( ) - this.C ) ) + this.D
newY = Math.round( newY )if (( this.A > 0 && newY > this.currentY ) ||
( this.A < 0 && newY < this.currentY )) {
if ( this.isIE )this.chaserDiv.style.pixelTop = newY
else this.chaserDiv.top = newY
}
}</SCRIPT>
</BODY>
</HTML>
<HEAD>
<STYLE TYPE='text/css'>
#myChaser {
position:absolute;
left:0px;
top:0px;
width:400px;
color:#555555;
font-family:宋体;
font-size:11pt;
}
</STYLE>
</HEAD><BODY>
<DIV ID='myChaser'></DIV>
<SCRIPT LANGUAGE='JavaScript'>var lefttime = 3600 //总时间function tim()
{
document.all.myChaser.innerHTML = "<b>剩余时间:<font color=red>" + lefttime + "</font>秒,你可以转换成时分秒的形式来显示</b>"
lefttime--
setTimeout("tim()",1000)
}
tim()var oChaser = {
topMargin : 0,
callRate : 1,
slideTime : 10,
maxDiff : document.all ? document.body.clientHeight : window.innerHeight,
isIE : document.all ? true : false,
chaserDiv : document[document.all ? "all" : "layers"]["myChaser"]
}window.setInterval("oChaser.main( )", oChaser.callRate)
oChaser.main = function( )
{
this.currentY = this.isIE ? this.chaserDiv.style.pixelTop : this.chaserDiv.top //pixelTop:该对象的top属性值,与top数值一样,但它是整型,不是字符型的值
this.scrollTop = this.isIE ? document.body.scrollTop : window.pageYOffset //scrollTop:顶部滚动过的距离
var newTargetY = this.scrollTop + this.topMarginif ( this.currentY != newTargetY ) { if ( newTargetY != this.targetY ) { this.targetY = newTargetY
this.slideInit( ) } this.slide( )
}
}oChaser.slideInit = function( )
{
var now = new Date( )this.A = this.targetY - this.currentY
this.B = Math.PI / ( 2 * this.slideTime )
this.C = now.getTime( )if (Math.abs(this.A) > this.maxDiff) {
this.D = this.A > 0 ? this.targetY - this.maxDiff : this.targetY + this.maxDiff
this.A = this.A > 0 ? this.maxDiff : -this.maxDiff
} else {
this.D = this.currentY
}
}oChaser.slide = function( )
{
var now = new Date( )
var newY = this.A * Math.sin( this.B * ( now.getTime( ) - this.C ) ) + this.D
newY = Math.round( newY )if (( this.A > 0 && newY > this.currentY ) ||
( this.A < 0 && newY < this.currentY )) {
if ( this.isIE )this.chaserDiv.style.pixelTop = newY
else this.chaserDiv.top = newY
}
}</SCRIPT>
</BODY>
</HTML>
解决方案 »
- javascript王者归来 这本书与 javascript权威指南 比较不知道哪个更好。。,还有 JavaScript网页特效范例宝典 明日科技的特效书
- 为什么我在客户端保存为html可以,但是在服务器上面运行就不可以?
- 怎么才能让它们一直循环呢,代码如下
- 请教高手:如何保存改动过后的网页,万分感谢!
- 请教各位,这两种编程方式的利弊?
- js是怎么调用activex的输出函数的
- javascript怎样读取表单数据?怎样提交到数据库?
- 老问题,我要移动光标,前一个,后一个,怎么动
- Can you help me???
- 两个问题请教 JS 高手……
- 怎么才能得到innerHTML中的ID中的值?
- 其实 functionInstance 的 toString 挺有用的
<head>
<script language=javascript>
var i=0;
function func(){
var aDate=new Date;
var tmpInt=Date.parse(txtTest2.value)-aDate;
var tmpHour,tmpMinute,tmpSecond;
tmpHour=parseInt(tmpInt/(1000*60*60));
tmpMinute=parseInt((tmpInt-tmpHour*1000*60*60)/(1000*60));
tmpSecond=parseInt((tmpInt-tmpHour*1000*60*60-tmpMinute*1000*60)/1000);
txtTest1.value=tmpHour+"小时"+tmpMinute+"分钟"+tmpSecond+"秒";
setTimeout('func()',100);
}
</script>
</head>
<body onload="func()">
离<input type=text name=txtTest2 value="2002/06/23 10:10:11">还有
<input type=text name=txtTest1 value="">
<BODY>
</body>
</html>
net_lover,你的答案非常详实.我把你的代码单独生成一个文件能实现上述功能.但将代码复制到我的文件中后,它就不随我的滚动条到滚动了,不知什么原因!我的那个文件是实现从数据库中随机调入20选择道题.
<HEAD>
<STYLE TYPE='text/css'>
#myChaser {
position:absolute;
left:0px;
top:0px;
width:400px;
color:#555555;
font-family:宋体;
font-size:11pt;
}
</STYLE>
</HEAD><BODY>
<DIV ID='myChaser'></DIV>
<SCRIPT LANGUAGE='JavaScript'>var lefttime = 3600 //总时间function tim()
{
document.all.myChaser.innerHTML = "<b>剩余时间:<font color=red>" + lefttime + "</font>秒,你可以转换成时分秒的形式来显示</b>"
lefttime--
setTimeout("tim()",1000)
}
tim()var oChaser = {
topMargin : 0,
callRate : 1,
slideTime : 10,
maxDiff : document.all ? document.body.clientHeight : window.innerHeight,
isIE : document.all ? true : false,
chaserDiv : document[document.all ? "all" : "layers"]["myChaser"]
}window.setInterval("oChaser.main( )", oChaser.callRate)
oChaser.main = function( )
{
this.currentY = this.isIE ? this.chaserDiv.style.pixelTop : this.chaserDiv.top //pixelTop:该对象的top属性值,与top数值一样,但它是整型,不是字符型的值
this.scrollTop = this.isIE ? document.body.scrollTop : window.pageYOffset //scrollTop:顶部滚动过的距离
var newTargetY = this.scrollTop + this.topMarginif ( this.currentY != newTargetY ) { if ( newTargetY != this.targetY ) { this.targetY = newTargetY
this.slideInit( ) } this.slide( )
}
}oChaser.slideInit = function( )
{
var now = new Date( )this.A = this.targetY - this.currentY
this.B = Math.PI / ( 2 * this.slideTime )
this.C = now.getTime( )if (Math.abs(this.A) > this.maxDiff) {
this.D = this.A > 0 ? this.targetY - this.maxDiff : this.targetY + this.maxDiff
this.A = this.A > 0 ? this.maxDiff : -this.maxDiff
} else {
this.D = this.currentY
}
}oChaser.slide = function( )
{
var now = new Date( )
var newY = this.A * Math.sin( this.B * ( now.getTime( ) - this.C ) ) + this.D
newY = Math.round( newY )if (( this.A > 0 && newY > this.currentY ) ||
( this.A < 0 && newY < this.currentY )) {
if ( this.isIE )this.chaserDiv.style.pixelTop = newY
else this.chaserDiv.top = newY
}
}</SCRIPT>
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
<br>滚动~
</BODY>
</HTML>
谢谢各侠关照,给分!不过,我想让时间出现在右下角,将如何修改原代码?