Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7977395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:11:08+00:00 2026-06-04T09:11:08+00:00

I’m creating a simple drag and drop game with jquery’s draggable plugin. There are

  • 0

I’m creating a simple drag and drop game with jquery’s draggable plugin.

There are 4 shapes, circle, square, triangle and star, and 4 drop off areas in divs:

<div class="drag">
    <div class="container">
        <div id="circle"></div>
    </div>
    <div class="container">
        <div id="square"></div>
    </div>
    <div class="container">
        <div id="triangle"></div>
    </div>
    <div class="container">
        <div id="star"></div>
    </div>
</div>
<div class="drop">
    <div class="container">
        <div id="circle"></div>
    </div>
    <div class="container">
        <div id="square"></div>
    </div>
    <div class="container">
        <div id="triangle"></div>
    </div>
    <div class="container">
        <div id="star"></div>
    </div>
</div>  

This for example is the info for circle (please imagine the same with the rest of the shapes):

function init() {
$('.drag #circle').data('shape','circle').draggable({
    cursor: 'move',
    stack: '#circle',
    revert: true
});
    $('.drop #circle').data('shape','circle').droppable( {
        accept: '#circle',
        drop: handleDropEvent
    } );
};
init();

This is the handle drop event:

function handleDropEvent( event, ui ) {
    var item = $(this).data('shape');
    var drop = $(this).data('shape');
    var dragItem = ui.draggable;
    if (item==drop){
        dragItem.position( { of: $(this), my: 'left top', at: 'left top' } );
        dragItem.draggable( 'option', 'revert', false );
        dragItem.draggable( 'disable' );
        $(this).droppable( 'disable' );
        correctMatch++;

    } 
    if ( correctMatch == 4 ) {
        $('.replay').show();
        $('.replay').click(function(){
            init();
        });
    }
}

Now in the replay class is a replay button. How do I have my shapes revert back to their original position?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:11:10+00:00Added an answer on June 4, 2026 at 9:11 am

    You could rebuild all from scratch, if you saved the original position, and then make it all draggable again. The easiest way is of course reloading the page, but I’m assuming you don’t want to do that. Therefore, I can think of several ways to go:
    1) When the document is ready, save enough information to rebuild the items from scratch in an array. I see you have 4 classes: circle, square, triangle and star. Just store the IDs in order in an array

    var initial_state=['circle', 'square', 'triangle', 'star']
    

    and then whenever the user clicks in the replay button you use this info to rebuild.

    $('.drag, .drop').html('')//Clean up the containers
    var a='';
    for (i in initial_state){
        a+='<div class="container" ><div id="'+i+'"></div></div>';//generate the html to append
    }
    $('.drag, .drop').append(a);//append it to the containers
    

    then you would have to bind again the draggable function, because the DOM has changed.

    2)Use the same array but MOVE the actual items to their positions. This can become a nightmare of selectors, but it is possible. You can always asign a DOM element to a var, and then move it at will through the page:

    var circle= $('.drag.container #star').eq[0]
    

    With eq you select the first/second/etc element from a set of elements. You have to make sure you are selecting just one element for your code to behave properly. Take into consideration that you have repeated ids in your html code. This is something you want to avoid, change them to classes or this kind of manipulation will become tricky at best.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.