Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript大小调整-IndexSizeError:索引或大小为负或大于允许的数量_Javascript_Jquery_Html - Fatal编程技术网

Javascript大小调整-IndexSizeError:索引或大小为负或大于允许的数量

Javascript大小调整-IndexSizeError:索引或大小为负或大于允许的数量,javascript,jquery,html,Javascript,Jquery,Html,这个脚本在Chrome上运行良好 它在Firefox上传播了大量错误 下面是给出错误的代码: var ctx = document.getElementById('canvas').getContext('2d'), img = new Image, sourceWidth = coordinates(one).w, sourceHeight = coordinates(one).h, sourceX = coordinates(one).x, sourc

这个脚本在Chrome上运行良好

它在Firefox上传播了大量错误

下面是给出错误的代码:

var ctx = document.getElementById('canvas').getContext('2d'),
    img = new Image,
    sourceWidth = coordinates(one).w,
    sourceHeight = coordinates(one).h,
    sourceX = coordinates(one).x,
    sourceY = coordinates(one).y;

    img.src = coordinates(one).image;

    img.onload = function() {
    // draw image
    ctx.drawImage(img, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, width, height);
这些坐标来自另一个函数:

// get cropped coordinates
        coordinates = function coordinates(self) {

            var imgInfo = self.imgInfo,
                c = self.eles.container,
                img = self.eles.img,
                imgsrc = img.attr('src'),

                coordinates = {
                    x: (parseInt(img.css('left'))) * (imgInfo.aw / (imgInfo.w * imgInfo.s)),
                    y: (parseInt(img.css('top'))) * (imgInfo.ah / (imgInfo.h * imgInfo.s)),
                    w: (c.width() - (40*2)) * (imgInfo.aw / (imgInfo.w * imgInfo.s)),
                    h: (c.height() - (40*2)) * (imgInfo.ah / (imgInfo.h * imgInfo.s)),
                    image: imgsrc
                };

            // return coodinates
            return coordinates;
        }
我想用滑块调整图像的大小,并居中。它在铬上工作得非常好


我能做什么?下面是测试代码的URL:nestecha.fr/cropScript

您会遇到什么错误?确切地说:IndexSizeError:Index或size为负数或大于允许的数量…x.drawImage(img,sourceX,sourceY,sourceWidth,sourceHeight,0,0,width,heigh…@AlexP错误是问题的标题。您可以添加jsfiddle吗?()你期望得到什么样的结果?你实际得到了什么样的结果?你得到了什么样的错误以及错误在哪里?我添加了它。在Chrome上尝试一下,我期望得到完全相同的结果。只需使用滑块,图像应该调整大小,以便在左侧画布中变得越来越小(这很有效)。然后,单击“裁剪”将在右侧生成新的已调整大小的图像(该图像不起作用,并抛出上面引用的错误)。