最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
jquery延迟处理和定时执行代码例子
时间:2014-05-09 编辑:简简单单 来源:一聚教程网
1、不应该用sleep,javascript又没有多线程,sleep了就阻塞了。
可以参考这个问题说明js是单线程的原理。
应该换个思路,用setInterval来实现循环。.
代码如下 | 复制代码 |
$("#list div.left").mouseover(function(){ var item=$(this).attr("id"); //alert(item); t = setTimeout(function(){ $("#"+item).parents("div.oitem").animate({width:"292"},400); $("#"+item).parents("div.oitem").siblings("div").animate({width:"126"},400); },100); }).mouseout(function(){ clearTimeout(t); }); |
2、在jquery 1.4中新增了一个叫delay(time);也可以现实延迟执行 time为延迟时间 1000=1s
代码如下 | 复制代码 |
$("button").click(function() { |
函数可直接用于动画过程中的延时环节,不过它没有callback参数,不能直接用来做定时器。
Added to jQuery in version 1.4, the .delay() method allows us to delay the execution of functions that follow it in the queue. It can be used with the standard effects queue or with a custom queue. Only subsequent events in a queue are delayed; for example this will not delay the no-arguments forms of .show() or .hide() which do not use the effects queue.
这是JQuery文档里对.delay()方法的说明,也就是只有后延的事情才会被加入delay()的队列当中。
-
下一个: 深入分析HTML头部标签用法
相关文章
- HTML简单购物数量小程序代码展示 10-31
- html canvas实现弹幕功能 10-31
- HTML中空格表示的意义 10-31
- html area标签解读 10-31
- html使用表单标签实现注册页面代码展示 10-31
- 使用HTML截图并保存为本地图片的代码展示 10-31