http://jsfiddle.net/eGjak/503/
당신은 다음 (피타고라스의 정리, aSquared + BSQUARE = cSquared 생각) 거리를 계산하고, 거리의 반경보다 작은 경우를 참조하십시오 캔버스의 로컬 x와 y를 찾을 수있다 이 트릭을해야하지만 원, 현재 속도에 저장하기 위해 다른이 작업을 수행 할 수있는 방법과 방법이 있습니다
var focused_circle, lastX, lastY ;
function test_distance(n, test_circle){ //see if the mouse is clicking circles
var dx = lastX - test_circle.x,
dy = lastY - test_circle.y;
//see if the distance between the click is less than radius
if(dx * dx + dy * dy < test_circle.r * test_circle.r ){
focused_circle = n;
$(document).bind('mousemove.move_circle' , drag_circle);
$(document).bind('mouseup.move_circle' , clear_bindings);
return false; // in jquery each, this is like break; stops checking future circles
}
}
$('#cv').mousedown(function(e){
lastX = e.pageX - $(this).offset().left;
lastY = e.pageY - $(this).offset().top;
$.each(circles, test_distance);
});
function drag_circle(e){
var newX = e.pageX - $('#cv').offset().left,
newY = e.pageY - $('#cv').offset().top;
//set new values
circles[ focused_circle ].x += newX - lastX;
circles[ focused_circle ].y += newY - lastY;
//remember these for next time
lastX = newX, lastY = newY;
//clear canvas and redraw everything
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
drawCircle(mainCircle);
$.each(circles, function() {
drawCircle(this);
drawLine(mainCircle, this);
});
}
function clear_bindings(e){ // mouse up event, clear the moving and mouseup bindings
$(document).unbind('mousemove.move_circle mouseup.move_circle');
focused_circle=undefined;
}
이
코드 후이 코드를 추가 (일명 마우스를 원 안에).
캔버스 대신 SVG를 사용하고 싶을 것 같아요. – pollirrata
svg 또는 some examples pleace에 대한 링크가 있습니다. –
google에서 검색 중이고? – pollirrata