如何通过jquery单独管理许多setInterval函数
How to manage many setInterval function by jquery each individually
嘿,我有一个 setInterval 函数 [见下文] 对于所有带有类的div 的每个函数,我的问题是以不同的方式管理每个div
请帮忙
var div_holder = $('div.products_each');
div_holder.each(function(i){
var vari= setInterval(function() {
//do something here
},1000/60)
});
我可以关闭它
$(document).on("mouseenter", ".products_each_all",function(){
$(this).children('div._title').css('margin-left',"0px");
clearInterval(vari);
})
此清除所有设置间隔调用 [影响所有div 操作]
我的问题是如何以不同的方式管理每个类设置间隔
提前致谢
使用 .data() 单独存储每个元素的间隔引用。
var div_holder = $('div.products_each');
div_holder.each(function (i) {
var vari = setInterval(function () {
//do something here
}, 1000 / 60)
$(this).data('vari', vari)
});
$(document).on("mouseenter", ".products_each_all", function () {
$(this).children('div._title').css('margin-left', "0px");
//each products_each element will have a data item called vari which holds the interval reference, you can use it to clear it later
var div_holder = $('div.products_each');
div_holder.each(function (i) {
clearInterval($(this).data('vari'));
});
})
你可以像这样实现它:
$.each($(".products_each"), function (index, value) {
var vari = setInterval(function() {
// do what ever you want with value
// it is your div : $(value).hide();
}, 1000/60);
});
相关文章:
- node.js:setInterval()正在跳过调用
- 为什么在许多浏览器中drawImage()的性能略好于createPattern()
- setInterval和clearInterval javascript无法按需工作
- Don'我不明白为什么我的setInterval+jQuery;不起作用
- setInterval游戏循环的范围问题
- 在Nodejs中为许多用户处理计时器
- JavaScript setInterval problems
- 如何在Javascript中延迟setInterval
- 当有许多形式时,Fancybox脚本不起作用
- 如何动态创建许多Jquery颜色选择器(eyecon)
- 我如何编程许多不同的条件和操作
- 如何执行相同的setInterval()
- SetInterval在javascript对象中表现怪异
- 从setInterval方法移动到带有sprite的requestAnimationFrame
- 如何在悬停时暂停setInterval
- 可以't获取setInterval函数以使用javascript中的this.function_name调用另一
- 删除对象时终止setInterval
- 使用setInterval()函数进行图像闪烁
- “;对于“;内部”;setInterval”;
- 如何通过jquery单独管理许多setInterval函数