[英]Uncaught RangeError: Maximum call stack size exceeded - jQuery Error
[英]jQuery Error - Maximum call stack size exceeded
我知道這個jQuery錯誤是問題所在。 但是您可能會看到,此錯誤對於解決問題根本沒有太大幫助。 我使用jQuery 1.10.2,並包含一個名為jRumble的1.3版插件。
現在該腳本附帶了錯誤:
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();
}
我的代碼有什么問題? 我認為可能是jQuery 1.10的語法錯誤。
謝謝你的幫助!
將animateScoll()
放入complete
回調中。 您不希望這樣一遍又一遍地調用它。
function animateScroll() {
jQuery('.landing-bar').animate({
width: '100%'
}, {
duration: 30000,
easing: 'linear',
complete:function() {
jQuery(this).css("width","0%");
animateScroll();
}
});
}
說明:
動畫complete
將調用jQuery回調complete
。 實際上,您要做的是一遍又一遍(在上次調用的毫秒內)調用animate函數,並使用永無止境的遞歸函數填充解釋器堆棧。
堆棧看起來像:
animateScroll()
animateScroll()
animateScroll()
animateScroll()
animateScroll()
...
您需要的是:
animateScroll()
animateScroll()
complete:function()
animateScroll()
complete:function()
animateScroll()
complete:function()
animateScroll()
...
這樣,每個步驟就可以在調用新步驟之前完成。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.