建設的實際實施將是麻煩,但這裏是一個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。 –