Javascript 尝试使用jQuery将负载附加到img时超出了最大调用堆栈大小
我选择了一个简单的图像(我也尝试了Javascript 尝试使用jQuery将负载附加到img时超出了最大调用堆栈大小,javascript,jquery,file-upload,Javascript,Jquery,File Upload,我选择了一个简单的图像(我也尝试了on()和one()): 由于某些原因,我得到了未捕获范围错误:超过了最大调用堆栈大小。如果有必要,我将从S3实例加载这些图像。我知道它确实重定向了几次,但我认为这无关紧要 有没有人遇到过这样或类似的事情。我觉得这不应该是一个无限循环。这种情况也会间歇性发生,这更令人困惑 调整大小的内容: publicMethod.resize = function (options) { if (open) { options = options ||
on()
和one()
):
由于某些原因,我得到了未捕获范围错误:超过了最大调用堆栈大小
。如果有必要,我将从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);
}
};
publicMethod.resize=函数(选项){
如果(打开){
选项=选项| |{};
如果(选项宽度){
settings.w=设置尺寸(options.width,'x')-加载宽度-接口宽度;
}
如果(选项.内部宽度){
settings.w=setSize(options.innerWidth,'x');
}
$loaded.css({width:settings.w});
如果(选项.高度){
settings.h=设置尺寸(options.height,'y')-加载高度-接口高度;
}
如果(选项.内部高度){
settings.h=setSize(options.innerHeight,'y');
}
如果(!options.innerHeight&&!options.height&&$loaded.find('iframe')。长度==0){
var$child=$loaded.wrapInner(“”.children();//临时包装器,用于准确估计总内容的大小。
settings.h=$child.height();
$child.replaceWith($child.children());//丢弃高度计算中使用的临时包装div
}
如果(选项中的“滚动顶部”){
settings.scrollTop=options.scrollTop;
}
$loaded.css({height:settings.h});
publicMethod.position(settings.transition==“none”?0:settings.speed);
}
};
经过几天的调试,我终于找到了问题所在。问题在于几个月前Paul Irish在Rails方面对一名开发人员进行了填隙,该开发人员否决了内部jQueryspecial.add
方法,该方法彻底破坏了任何img.load()
东西。代码片段看起来是这样的(实际上它在整个web上都部署了,但直到jQuery1.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的大型代码库中工作,并且在尝试加载图像时遇到调用堆栈超出的错误,则此垫片可能是在某个时候添加的。显示您的代码,您如何响应调整大小事件?我在一个庞大的代码库中工作,因此无法复制和粘贴所有内容。我将尝试获取所需内容呃,你在找tho。我已经添加了来自colorbox.js的调整大小代码。我们讨论了多少图像?一个。并且100%确定(即使我正在检查jQuery选项上的
.length
)我也试过选择img:first
你试过chrome的中断DOM事件调试标志吗?还有console.trace可以在给定的点上为你提供堆栈跟踪,或者只是在自己的行上放置“debugger”在你的resize函数中单步执行,看看每次调用它的是什么。(如果您已经意识到这一点,很抱歉,如果您没有最简单的示例,我会从这里开始)有任何更新吗?我也有同样的难题,但需要保留图像加载垫片来检测存储在缓存中的图像。@mrbinky3000这在jQuery中得到了修复。只有在使用超旧版本的jQuery(例如,
/*
* 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));