当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 延时重复执行函数 lLoopRun.js

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 延时重复执行函数 lLoopRun.js


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 118 ::
收藏到网摘: n/a

公司的一个项目中,有许多地方需要延时执行一些可重复性的函数(动作),就写了下面这段函数。
呵呵,不知道取什么意思更为确切些,就定为了:LoopRun,意为“重复执行”
function lLoopRun(sFuncLoop,sFuncEnd,nDelay) {
var vintervalId = null;
var runString = sFuncLoop;
var stopString = sFuncEnd;
var delayTime = nDelay;
//var nCount = 0;
this._doLoop = function (){
if (vintervalId && !eval(stopString)){
eval(runString);
//nCount++;
} else {
window.clearInterval(vintervalId);
vintervalId = null;
}
}
window.clearInterval(vintervalId);
vintervalId = window.setInterval(this._doLoop,delayTime);
}
参数说明:
sFuncLoop >> 字符串型,需要重复执行的Javascript函数或语句(多个函数或语句请用;分隔)
sFuncEnd >> 字符串型,用于中止重复执行动作(sFuncLoop)的Javascript函数或语句
nDelay >> 数字型,重复执行的时间间隔(毫秒数)
应用实例:
水平往复运动: http://cnlei.iecn.net/mycode/lLoopRun/index.html
自动伸缩大小: http://cnlei.iecn.net/mycode/lLoopRun/index2.html
垂直往复运动: http://cnlei.iecn.net/mycode/lLoopRun/index3.html
渐变显示(图片): http://cnlei.iecn.net/mycode/lLoopRun/index4.html
以上只是几个简单的应用实例,具体应用时关键还得看sFuncLoop和sFuncEnd这两个参数所代表的函数写得是否好,例如给实例一中的运动图片加上缓冲运行的效果的话,就需要在sFuncLoop所代表的函数中加上相应的实现代码:)