建设的实际实施将是麻烦,但这里是一个POC https://jsfiddle.net/f8h3j7v4/
c.addEventListener('mousedown',function(e){//c = context, check the fiddle
//Calculate the position of the edges, currently hardcoded values for fiddle
//For example getPosition(c).y + y * scaleY
//I should mention that rotate starts at the top left corner;
//the whole canvas gets rotated(+transform exists)
//There is actually a pretty clever way to handle rotation;
//rotate the mouse position
if(e.clientY > 15 && e.clientY < 25)
dragNorth = true
else
dragNorth = false
if(e.clientX > 15 && e.clientX < 25)
dragWest = true
else
dragWest = false
if(e.clientX > 165 && e.clientX < 175)
dragEast = true
else
dragEast = false
if(e.clientY > 165 && e.clientY < 175)
dragSouth = true
else
dragSouth = false
})
function getPosition(element) {
var xPosition = 0;
var yPosition = 0;
while(element) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return { x: xPosition, y: yPosition };
}
//Thanks to
//http://www.kirupa.com/html5/get_element_position_using_javascript.htm
只是calc下画布的位置,然后拖走:)
也许这会帮助你的http: //stackoverflow.com/a/26788306/826625(包括效果图) – mstoppert
我不熟悉的技术,但是你能不能calc下的区域?例如...可拖动的区域应该是宽度:0;宽度:currentWidth,高度相同。所有你必须知道的是图像开始的地方,这是矩形对象的x和y。 –