JQuery drag and drop to change the element size

Source: Internet
Author: User

In fact, the principle of "element drag and drop to change the size" is different from that of "element drag". It is mainly used for top, left, width, and height, relatively easy to implement. The following is a source code prototype. After you understand the principle and expand other practical applications, the idea is much simpler and clearer. Let's take a look at the effect:

Show me the results ~ By www.bkjia.com

Below is the JavaScript Code

<Script type = "text/javascript">/** jQuery. resize by wuxinxi007 * Date: 2011-5-14 */$ (function () {// bind the bindResize (document. getElementById ('test');}); function bindResize (el) {// initialization parameter var els = el. style, // X and Y axis coordinates of the mouse x = y = 0; // evil index finger $ (el ). mousedown (function (e) {// After the element is pressed, the coordinates x = e after the current mouse and object are calculated. clientX-el. offsetWidth, y = e. clientY-el. offsetHeight; // supports setCapture to do something else. setCapture? (// Capture focus el. setCapture (), // set the event el. onmousemove = function (ev) {mouseMove (ev | event)}, el. onmouseup = mouseUp): (// bind event $ (document ). bind ("mousemove", mouseMove ). bind ("mouseup", mouseUp) // prevents default events from occurring e. preventDefault ()}); // move event function mouseMove (e) {// Super invincible universe computing... els. width = e. clientX-x + 'px ', els. height = e. clientY-y + 'px '} // stop the event function mouseUp () {// do something like el in support of releaseCapture. releaseCapture? (// Release focus el. releaseCapture (), // remove event el. onmousemove = el. onmouseup = null): (// unload event $ (document ). unbind ("mousemove", mouseMove ). unbind ("mouseup", mouseUp) }}</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.