Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2010
    Location
    Armenia
    Posts
    41
    Thanks
    17
    Thanked 0 Times in 0 Posts

    jQuery draggable element jumps back to its initial position

    Hello there .
    I have some elements on my page that i have apllied jQuery's draggable function to them so I can drag them . Here is my question .
    Is there a function which will return the draggable object to its initial position(the position where it was when the page loaded ) when an event occurs (for example I draggeed it and put it in a droppable element ) ?

    Please I really need your help!!!
    Thank you in advance!!

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    Not quite clear what you're trying to do, but if you specify

    helper:'clone'

    as an option for .draggable() then the dragged element will remain where it is and a clone of the element will be dragged - so the original element does not move. Is that what you mean? So this would allow you to build, for example, a shopping cart where you can drag items to the cart but they remain available in the shop for multiple purchases.

    Otherwise, the revert option will cause the dragged element to return to it's original position when dragging stops.
    Last edited by SB65; 10-29-2011 at 11:51 AM.

  • Users who have thanked SB65 for this post:

    narek (10-29-2011)

  • #3
    New Coder
    Join Date
    Feb 2010
    Location
    Armenia
    Posts
    41
    Thanks
    17
    Thanked 0 Times in 0 Posts
    SB65 your post was really helpfull thank you.
    But i miss only one thing here. After i drag the clone and dropp in the appropriate "drop element" how can i make it to disapprear(I mean hide or do watever to make the dragged element to disappear from its initial place ) ? And also how to make the "dragged" element be on the dropped element(since in case of clone it disappears) ?

  • #4
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    To do something when the element is dropped it would be usual to write a function against the drop event:

    Code:
    $('#droppable').droppable({
    	drop:function(event,ui){
                   .... do things ......
    	}
    });
    So this code could add something into the droppable element or whatever as required.

  • Users who have thanked SB65 for this post:

    narek (10-29-2011)

  • #5
    New Coder
    Join Date
    Feb 2010
    Location
    Armenia
    Posts
    41
    Thanks
    17
    Thanked 0 Times in 0 Posts
    SB65 I found a solution to my problem
    $("#draggable").draggable({revert:true});
    However thank you very much!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •