"Element Drag to change the size" in fact, and "element drag" a principle, but the dynamic change of the object is different, mainly in the top, left, width, height of the use, relative implementation is also very easy. The following is attached to the source code prototype, to figure out the principle of further expansion of other practical applications, the idea becomes simple, much clearer. First to see the effect: Tahe County Xianqing Machinery
Below is the JavaScript Codeview source print?
01 |
<script type= "text/javascript" > |
03 |
* jQuery.Resize by wuxinxi007 |
08 |
bindResize(document.getElementById( ‘test‘ )); |
11 |
function bindResize(el){ |
17 |
$(el).mousedown( function (e){ |
18 |
//按下元素后,计算当前鼠标与对象计算后的坐标 |
19 |
x = e.clientX - el.offsetWidth, |
20 |
y = e.clientY - el.offsetHeight; |
26 |
el.onmousemove = function (ev){ |
27 |
mouseMove(ev || event) |
29 |
el.onmouseup = mouseUp |
32 |
$(document).bind( "mousemove" ,mouseMove).bind( "mouseup" ,mouseUp) |
40 |
els.width = e.clientX - x + ‘px‘ , |
41 |
els.height = e.clientY - y + ‘px‘ |
45 |
//在支持 releaseCapture 做些东东 |
50 |
el.onmousemove = el.onmouseup = null |
53 |
$(document).unbind( "mousemove" , mouseMove).unbind( "mouseup" , mouseUp) |
jquery Drag to change the dimensions of the element