예제를 작성하는 데 시간이 걸렸습니다. 그것은 여기 :
http://blixt.org/js/resize.html
(참고 :. 나는 그것을 크로스 브라우저 호환이었다 있는지 확인하는 시간을 고려하지 않았기 때문에 이것은 아마 모든 브라우저에서 작동하지 않습니다)
기본적으로 커서가 요소 가장자리에서 얼마나 멀리 떨어져 있는지 확인하기 위해 mousemove
이벤트를 사용하고, 가장자리에 충분히 근접하면 해당 가장자리에 커서를 표시합니다. 자바 스크립트는 다음과 같습니다 :
(참고 : 실제 프로젝트에서는 크로스 브라우저 호환성, 유지 보수성 및 라이브러리 간의 상호 작용을 위해이 코드를 매우 다르게 지정할 것입니다. 개발자는 jQuery과 같은 프레임 워크를 사용해야합니다. 이 모든 것들에 대해 이미 생각했다.)
var r = document.getElementById('resizable');
r.onmousemove = function (e) {
if (!e) e = window.event;
var
// Get the distances to all the edges.
// e.clientX is the X coordinate on the client area (window) of the mouse.
// r.offsetLeft is the horizontal offset from the page left.
// r.offsetWidth is the total width of the element.
left = e.clientX - r.offsetLeft, top = e.clientY - r.offsetTop,
bottom = r.offsetHeight - top, right = r.offsetWidth - left,
// Get the shortest distance to any of the edges.
min = Math.min(Math.min(Math.min(top, left), bottom), right);
// If the pointer is further than 5 pixels from an edge, do not display
// any resize cursor.
if (min > 5) {
r.style.cursor = 'default';
return;
}
// Determine which cursor to display.
switch (min) {
case top:
r.style.cursor = 'n-resize';
break;
case left:
r.style.cursor = 'w-resize';
break;
case bottom:
r.style.cursor = 's-resize';
break;
case right:
r.style.cursor = 'e-resize';
break;
}
}
OP에는 이미지가 언급되지 않았다. 게다가, 자바 스크립트로 클라이언트 clientside 이미지의 크기를 조정할 수 있습니다. 디스플레이의 크기 만 조절하는 것입니다. 약간의 수학 만 사용하면 추가 요소를 만들지 않고 크기 조정 영역을 만드는 방법이 있습니다. – Breton
두 번째 부분에서는 요소의 가장자리에만 커서를 사용할 수 없습니다. – rahul
커서가 전체 요소에 적용됩니다. 따라서 커서를 가장자리 위로 가져갈 때 크기를 변경해야 할 경우 별도의 요소를 만들어야합니다. – rahul