SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery drag and drop question

    Hi guys,

    I am using jQuery now. I can drag and drop.
    But I want to drag an IMG for example and I want the user ONLY to be able to drag it into a specific div, otherwise I want it to revert for example or just not work. Any idea's how i can do so?

    thanks

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank u ..
    but isnt there any more explanation about how to use it?
    or an example of this one?
    i checked the link but it doesnt explain a lot to me since i am new to jQuery and libraries in general

  4. #4
    SitePoint Member cogsprocket's Avatar
    Join Date
    Mar 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to make it so an item can only be dropped on a droppable and return to it's hope position otherwise you can use the following code.

    Code:
    $(".draggableItem").draggable({ revert: "invalid" });
    
    $(".droppableItem").droppable();
    Elements of the class "draggableItem" would only be droppable on elements of the class "droppableItem".

    This is really all you need to get the basic behavior. To do more, like having an item bounce into the bounds of a div and center itself (probably not what you're after) you'll need to do more code but this is really all you need to get the behavior you're after.


Bookmarks

Posting Permissions

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