1、思路
分为三步:
第一步:获取画布中加载的图像的尺寸大小;
第二步:获取当前画布的尺寸大小;
第三步:用图像尺寸和画布尺寸比较。
2、实现
第一步:
var imgWidth,imgHeight
img=new Image();
img.src = "./Images/123.png";
imgWidth = img.width
imgHeight = img.height
第二步:
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;
第三步:
//imgIconX、imgIconY 为图像拖动点的坐标
if (imgWidth + imgIconX < 0 ) {
x = 20
}
if (imgWidth + canvasWidth < imgIconX) {
x = -20
}
if (imgHeight + imgIconY < 0) {
y = 20
}
if (imgHeight + canvasHeight < imgIconY) {
y = -20
}