此脚本适用于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;
}
我想用滑块调整图像大小并居中。它在Chrome上完美运行。
我该怎么办?这是测试代码的URL:nestecha.fr/cropScript