我选择了一个简单的图像(我也尝试了 on()
和 one()
):
$container.find('.thumbnail img').load(function(){
$container.trigger('resize');
});
出于某种原因,我得到了 Uncaught RangeError: Maximum call stack size exceeded
。如果重要的话,我将从 S3 实例加载这些图像。我知道它确实重定向了几次,但我认为这无关紧要。
有没有人遇到过这个或类似的事情。我觉得这不应该是一个无限循环。这也会间歇性地发生,这更令人困惑。
调整大小的东西:
publicMethod.resize = function (options) {
if (open) {
options = options || {};
if (options.width) {
settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
}
if (options.innerWidth) {
settings.w = setSize(options.innerWidth, 'x');
}
$loaded.css({width: settings.w});
if (options.height) {
settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
}
if (options.innerHeight) {
settings.h = setSize(options.innerHeight, 'y');
}
if (!options.innerHeight && !options.height && $loaded.find('iframe').length == 0) {
var $child = $loaded.wrapInner("<div style='overflow:auto'></div>").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be.
settings.h = $child.height();
$child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation
}
if("scrollTop" in options) {
settings.scrollTop = options.scrollTop;
}
$loaded.css({height: settings.h});
publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
}
};
最佳答案
经过几天的调试,我终于找到了问题所在。问题是 Paul Irish 几个月前 Rails 方面的开发人员使用了一个垫片,它覆盖了内部 jQuery special.add
方法,该方法完全破坏了任何 img.load()
东西。该片段看起来像这样(它实际上部署在整个网络上,但在 jQuery 1.6-1.7+ 之前不会引起问题
/*
* Special event for image load events
* Needed because some browsers does not trigger the event on cached images.
* MIT License
* Paul Irish | @paul_irish | www.paulirish.com
* Andree Hansson | @peolanha | www.andreehansson.se
* 2010.
*
* Usage:
* $(images).bind('load', function (e) {
* // Do stuff on load
* });
*
* Note that you can bind the 'error' event on data uri images, this will trigger when
* data uri images isn't supported.
*
* Tested in:
* FF 3+
* IE 6-8
* Chromium 5-6
* Opera 9-10
*/
(function ($) {
$.event.special.load = {
add: function (hollaback) {
if ( this.nodeType === 1 && this.tagName.toLowerCase() === 'img' && this.src !== '' ) {
// Image is already complete, fire the hollaback (fixes browser issues were cached
// images isn't triggering the load event)
if ( this.complete || this.readyState === 4 ) {
hollaback.handler.apply(this);
}
// Check if data URI images is supported, fire 'error' event if not
else if ( this.readyState === 'uninitialized' && this.src.indexOf('data:') === 0 ) {
$(this).trigger('error');
}
else {
$(this).bind('load', hollaback.handler);
}
}
}
};
}(jQuery));
因此,如果您正在处理使用 jQuery 的大型代码库,并且在尝试执行图像加载时遇到调用堆栈超出错误,则可能是在某个时候添加了此 shim。
关于javascript - 尝试使用 jQuery 将负载附加到 img 时超出最大调用堆栈大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9642566/