时钟HTC

本文属spanzhang原创,其blog地址为:http://blog.csdn.net/spanzhang。引用请注明出处,谢谢!!

  <!--

作者:张友邦
时间:2004-02-27
描述:时钟控件
属性:
 unit  :时间单位,它本身以毫秒为单位。时钟将以该单位迈进,每一次增加都会产生一个事件onunit。
 interval :时钟目标所包含的单位(unit)数。
 unitCount :当前经过的单位数。
 enabled  :时钟使能状态。
事件:
 onunit  :每一次时钟迈进产生的事件。
 ontimer  :时钟目标事件。

实例:
 <span id="timer1"
   style="behavior:url(spanTimer.htc); color:red; cursor:hand;"
   οnclick="this.enabled = !this.enabled;"
   interval=10
   onunit="onEveryUnit()"
   ontimer="refreshData();"
   title="停止/启动"></span>
-->

<!--
 接口定义
-->
<public:component>
<public:property name="description" value="Span Timer Behavior"    />
<public:property name="version"  value="1.0.0.0"       />

<public:property name="unit"   put=putUnit   get=getUnit   />
<public:property name="interval"  put=putInterval  get=getInterval  />
<public:property name="enabled"  put=putEnabled  get=getEnabled  />
<public:property name="unitCount"      get=getUnitCount />

<public:method  name="reset"            />

<public:event  name="onunit"  id="eventUnit"       />
<public:event  name="ontimer"  id="eventTimer"       />
</public:component>


<!--
 组件实现
-->

<script language="javascript">

//
//
全局变量
//
var __handleInterval = null;
var __unitCount  = 0
var __enabled = false
var __unit = 1000
var __interval = 10

//
//
单位毫秒数
//
function putUnit(unitInMS)
{
__unit
= unitInMS
__startTimer()
}
function getUnit()
{
return __unit
}

//
//
当前单位数
//
function getUnitCount()
{
return __unitCount
}

//
//
实际的时钟处理函数
//
function __timerEventHandler()
{
__unitCount
++
eventUnit.fire(createEventObject())

if (__unitCount >= __interval)
{
  eventTimer.fire(createEventObject())
  __unitCount
= 0
}
}

//
//
时钟控制函数
//
function __stopTimer()
{
if (__handleInterval != null)
{
  clearInterval(__handleInterval)
  __handleInterval
= null
}

__unitCount
= 0
}
function __startTimer()
{
__stopTimer()
__handleInterval
= setInterval(__timerEventHandler, __unit)
eventUnit.fire(createEventObject())
}

//
//
时钟周期
//
function putInterval(intervalInSeconds)
{
__interval
= intervalInSeconds

if (__enabled)
{
  __startTimer()
//restart
}
}
function getInterval()
{
return __interval
}

//
//
时钟状态
//
function putEnabled(beEnabled)
{
if (__enabled == beEnabled)
 
return

if (beEnabled)
  __startTimer() 
else
  __stopTimer()

__enabled
= beEnabled
}
function getEnabled()
{
return __enabled
}

//
//
重置
//
function reset()
{
__unitCount
= 0
if (__enabled)
  __startTimer()
}
</script> <script language=javascript> // // 全局变量 // var __handleInterval = null; var __unitCount = 0 var __enabled = false var __unit = 1000 var __interval = 10 // // 单位毫秒数 // function putUnit(unitInMS) { __unit = unitInMS __startTimer() } function getUnit() { return __unit } // // 当前单位数 // function getUnitCount() { return __unitCount } // // 实际的时钟处理函数 // function __timerEventHandler() { __unitCount++ eventUnit.fire(createEventObject()) if (__unitCount >= __interval) { eventTimer.fire(createEventObject()) __unitCount = 0 } } // // 时钟控制函数 // function __stopTimer() { if (__handleInterval != null) { clearInterval(__handleInterval) __handleInterval = null } __unitCount = 0 } function __startTimer() { __stopTimer() __handleInterval = setInterval(__timerEventHandler, __unit) eventUnit.fire(createEventObject()) } // // 时钟周期 // function putInterval(intervalInSeconds) { __interval = intervalInSeconds if (__enabled) { __startTimer() //restart } } function getInterval() { return __interval } // // 时钟状态 // function putEnabled(beEnabled) { if (__enabled == beEnabled) return if (beEnabled) __startTimer() else __stopTimer() __enabled = beEnabled } function getEnabled() { return __enabled } // // 重置 // function reset() { __unitCount = 0 if (__enabled) __startTimer() } </script> <script language=javascript> // // 全局变量 // var __handleInterval = null; var __unitCount = 0 var __enabled = false var __unit = 1000 var __interval = 10 // // 单位毫秒数 // function putUnit(unitInMS) { __unit = unitInMS __startTimer() } function getUnit() { return __unit } // // 当前单位数 // function getUnitCount() { return __unitCount } // // 实际的时钟处理函数 // function __timerEventHandler() { __unitCount++ eventUnit.fire(createEventObject()) if (__unitCount >= __interval) { eventTimer.fire(createEventObject()) __unitCount = 0 } } // // 时钟控制函数 // function __stopTimer() { if (__handleInterval != null) { clearInterval(__handleInterval) __handleInterval = null } __unitCount = 0 } function __startTimer() { __stopTimer() __handleInterval = setInterval(__timerEventHandler, __unit) eventUnit.fire(createEventObject()) } // // 时钟周期 // function putInterval(intervalInSeconds) { __interval = intervalInSeconds if (__enabled) { __startTimer() //restart } } function getInterval() { return __interval } // // 时钟状态 // function putEnabled(beEnabled) { if (__enabled == beEnabled) return if (beEnabled) __startTimer() else __stopTimer() __enabled = beEnabled } function getEnabled() { return __enabled } // // 重置 // function reset() { __unitCount = 0 if (__enabled) __startTimer() } </script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值