Javascript jQuery错误-超过最大调用堆栈大小
我知道有很多问题是jQuery错误造成的。但是,您可能会发现,这个错误对解决问题毫无帮助。我使用jQuery1.10.2,并在版本1.3中包含了一个名为jRumble的插件 现在,此脚本会出现错误:Javascript jQuery错误-超过最大调用堆栈大小,javascript,jquery,Javascript,Jquery,我知道有很多问题是jQuery错误造成的。但是,您可能会发现,这个错误对解决问题毫无帮助。我使用jQuery1.10.2,并在版本1.3中包含了一个名为jRumble的插件 现在,此脚本会出现错误: jQuery(document).ready(function() { jQuery('.landing-bar').jrumble({ x: 1, y: 1, rotation: 0 }); var rumbleStart
jQuery(document).ready(function() {
jQuery('.landing-bar').jrumble({
x: 1,
y: 1,
rotation: 0
});
var rumbleStart = function() {
jQuery('.landing-bar').trigger('startRumble');
setTimeout(rumbleStop, 200);
};
var rumbleStop = function() {
jQuery('.landing-bar').trigger('stopRumble');
setTimeout(rumbleStart, 785);
};
rumbleStart();
animateScroll();
});
function animateScroll() {
jQuery('.landing-bar').animate({
width: '100%'
}, {
duration: 30000,
easing: 'linear',
complete:function() {
jQuery(this).css("width","0%");
}
});
animateScroll();
}
我的代码有什么问题?我认为jQuery1.10的语法可能是错误的
谢谢你的帮助 将animateScoll()
放入complete
回调中。你不希望它被这样一遍又一遍地叫
function animateScroll() {
jQuery('.landing-bar').animate({
width: '100%'
}, {
duration: 30000,
easing: 'linear',
complete:function() {
jQuery(this).css("width","0%");
animateScroll();
}
});
}
说明:
动画制作完成后,将调用jQuery回调complete
。实际上,您要做的是反复调用animate函数(在上一次调用的毫秒内),并用一个永不结束的递归函数填充解释器堆栈
堆栈将如下所示:
animateScroll()
animateScroll()
animateScroll()
animateScroll()
animateScroll()
...
您需要的是:
animateScroll()
animateScroll()
complete:function()
animateScroll()
complete:function()
animateScroll()
complete:function()
animateScroll()
...
因此,在调用新步骤之前,每个步骤都会完成。在
animateScroll
中会出现无限递归。。。。你为什么在animateScroll
内部调用animateScroll
你有小提琴吗?抛出错误时调用什么方法?使用setTimeout(animateScroll,30000)
而不是直接调用animateScroll,或者在animate done中调用animateScroll()
callback@ArunPJohny那一定是那样的。这是一个加载条,当它达到100%宽度时,应开始变为100%。。难道我不能这样做吗?@ArunPJohny希望能够一次又一次地开始整个“成长到100%”过程