Jquery-based Drag layout plug-in _ jquery

Source: Internet
Author: User
Jquery-based Drag layout plug-in. For more information, see. The Code is as follows:


(Function ($ ){
$. Fn. lsMovePanel = function (){
Var id = this. attr ("id ");
Var X = Y = 0;
Var offsetX = offsetY = 0; // absolute position
Var OldIndex = 0; // store the original Index
Var Temp_Li ="

  • ";
    Var Move_obj; // the object to be dragged.
    $ ("#" + Id + "li"). each (function (I ){
    $ (This). attr ("open", "0 ");
    // Click
    $ (This). bind ("mousedown", function (){
    If (event. button = 1 | event. button = 0) {$ (this). attr ("open", "1 ");}
    If ($ (this). attr ("open") = "1 "){
    Certificate (this).css ({
    Cursor: "move ",
    Opacity: "0.7"
    });
    X = event. clientX;
    Y = event. clientY;
    OffsetX = $ (this). offset (). left;
    OffsetY = $ (this). offset (). top;
    OldIndex = $ (this). index ();
    Certificate (this).css ({
    Position: "absolute ",
    Left: offsetX,
    Top: offsetY
    });
    $ ("#" + Id + "li"). each (function (I ){
    If (I = OldIndex ){
    $ (This). after (Temp_Li );
    }
    })
    }
    });
    // Open the mouse
    $ (This). bind ("mouseup", function (){
    If (event. button = 1 | event. button = 0) {$ (this). attr ("open", "0 ");}
    If ($ (this). attr ("open") = "0 "){
    $ ("# Temp_Li"). before ($ (this ));
    $ (This). animate ({
    Left: $ ("# Temp_Li"). offset (). left,
    Top: $ ("# Temp_Li"). offset (). top,
    },300, function (){
    $ ("# Temp_Li"). remove ();
    Certificate (this).css ({
    Cursor: "default ",
    Opacity: "1 ",
    Position: "static"
    });
    });
    $ ("#" + Id + "li"). each (function (I ){
    Certificate (this).css ({
    "Border-color": "#666666"
    });
    });
    }
    });
    // Move
    $ (This). bind ("mousemove", function (){
    If ($ (this). attr ("open") = "1 "){
    Var current_X = current_Y = 0;
    Current_X = offsetX + event. clientX-X;
    Current_Y = offsetY + event. clientY-Y;
    Certificate (this).css ({
    Position: "absolute ",
    Left: current_X,
    Top: current_Y
    });
    Move_obj = this;
    $ ("#" + Id + "li"). each (function (I ){
    If (I! = OldIndex & $ (this). attr ("id ")! = "Temp_Li "){
    Var Deviation = 0;
    Var Max_X = $ (this). offset (). left + $ (this). width ()-Deviation;
    Var Min_X = $ (this). offset (). left + Deviation;
    Var Max_Y = $ (this). offset (). top + $ (this). height ()-Deviation;
    Var Min_Y = $ (this). offset (). top + Deviation;
    If (event. clientX <Max_X) & (event. clientY + $ (Move_obj ). height ()> Max_Y) & (event. clientY + $ (Move_obj ). height ()> Min_Y) & (event. clientX> Min_X) & (event. clientY <Max_Y )){
    Certificate (this).css ({
    "Border-color": "# FF7578"
    });
    // Determine whether to overwrite the object index value before or after
    If (OldIndex> $ (this). index ()){
    $ ("# Temp_Li"). before ($ (this ));
    $ ("# Temp_Li"). remove ();
    $ (This). before (Temp_Li );
    } Else {
    $ ("# Temp_Li"). after ($ (this ));
    $ ("# Temp_Li"). remove ();
    $ (This). after (Temp_Li );
    }
    } Else {
    Certificate (this).css ({
    "Border-color": "#666666"
    });
    }
    }
    })
    }
    });
    });
    }
    }) (JQuery );


    Call example:

    The Code is as follows:









    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.