Jquery plug-in jquery. dragscale. js implements the drag and drop method to change the element size (with demo source code download), jquery drag and drop drag

Source: Internet
Author: User

Jquery plug-in jquery. dragscale. js implements the drag and drop method to change the element size (with demo source code download), jquery drag and drop drag

This document describes how to drag and drop jquery. dragscale. js to change the element size. We will share this with you for your reference. The details are as follows:

This plug-in is written by the author of the article to improve the author's js capabilities. It also provides some convenience for some js cainiao to use the plug-in. Let's fly over it.

This plug-in is designed to achieve the effect of changing the size of elements by drag and drop. You can set the minimum width and maximum width of the elements to be dragged based on your actual needs. The overall code is as follows:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Jquery. dragscale. js code:

/** Resizable 0.1 * Dependenc jquery-1.7.1.js */; (function (a) {. fn. resizable = function (options) {var defaults = {// default parameter minW: 150, minH: 150, maxW: 500, maxH: 500,} var opts =. extend (defaults, options); this. each (function () {var obj = a (this); obj. mousedown (function (e) {var e = e | event; // differentiate IE from other browser event objects var x = e. pageX-obj. position (). left; // obtain the distance from the left of the parent element of the matching element. var y = e. pageY-obj. posi Tion (). top; // get the distance between the mouse and the top of the parent element of the matching element $ (document ). mousemove (function (e) {var e = e | event; var _ x = e. pageX-x; // Dynamically Retrieve the width of the matching element from the left of its parent element var _ y = e. pageY-y; _ x = _ x <opts. minW? Opts. minW: _ x; // ensure that the minimum width of the matching element is 150px _ x = _ x> opts. maxW? Opts. maxW: _ x; // ensure that the maximum width of the matching element is 500px _ y = _ y <opts. minH? Opts. minH: _ y; _ y = _ y> opts. maxH? Opts. maxH: _ y; obj.parent().css ({width: _ x, height: _ y });}). mouseup (function () {$ (this ). unbind ("mousemove"); // when the mouse is lifted to delete the movement event, the matching element width and height change is stopped.}) ;}}) (jQuery );

Click here to download the complete instance code.

Related Article

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.