延时重复执行函数 lLoopRun.js
时间:2024-05-13 09:20:24
公司的一个项目中,有许多地方需要延时执行一些可重复性的函数(动作),就写了下面这段函数。
呵呵,不知道取什么意思更为确切些,就定为了: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所代表的函数中加上相应的实现代码:)
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python使用lxml模块和Requests模块抓取HTML页面的教程
pygame游戏之旅 按钮上添加文字的方法
![](https://img.aspxhome.com/file/2023/3/87753_0s.jpg)
favicon.ico以及动态图片的实现
PHP在线打包下载功能示例
![](https://img.aspxhome.com/file/2023/7/122527_0s.png)
Python实例练习水仙花数问题讲解
![](https://img.aspxhome.com/file/2023/0/110440_0s.png)
Django中如何使用sass的方法步骤
Python selenium根据class定位页面元素的方法
![](https://img.aspxhome.com/file/2023/2/127742_0s.png)
浅析SQL Server中包含事务的存储过程
Python执行Linux系统命令的4种方法
深入理解Python虚拟机中字节(bytes)的实现原理及源码剖析
![](https://img.aspxhome.com/file/2023/1/124731_0s.png)
关于mysql中的json解析函数JSON_EXTRACT
Laravel框架视图和模型操作方法分析
PythonPC客户端自动化实现原理(pywinauto)
![](https://img.aspxhome.com/file/2023/3/95673_0s.png)
Python抓包并解析json爬虫的完整实例代码
![](https://img.aspxhome.com/file/2023/5/120485_0s.png)
FrontPage XP中的设计技巧
一文带你吃透Python中的日期时间模块
![](https://img.aspxhome.com/file/2023/0/103670_0s.png)
使用Numpy读取CSV文件,并进行行列删除的操作方法
Python中使用socks5设置全局代理的方法示例
![](https://img.aspxhome.com/file/2023/8/98798_0s.jpg)