<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>

解决方案 »

  1.   

    <html>
    <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>
      

  2.   

    谢谢你们的答案,但我是一个新手,还有一些不懂的问题请教各位大哥!
    net_lover,你的答案非常详实.我把你的代码单独生成一个文件能实现上述功能.但将代码复制到我的文件中后,它就不随我的滚动条到滚动了,不知什么原因!我的那个文件是实现从数据库中随机调入20选择道题.
      

  3.   

    只需要增加你的内容即可,不要变其他的,例如这样:<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>
    <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>
      

  4.   

    问题已经解决了,原来我没有拷<style../style>中的内容。
    谢谢各侠关照,给分!不过,我想让时间出现在右下角,将如何修改原代码?