1

Sorry I'm a newb at this ... looking to click on a picture and drag it into another div but keeping the original picture in the same position and state. I had a go at this but failed! Thanks in advance for the help.

      <div id="#user3profile" >
          <img src="pic/user3.png" class="userprofilepic" id="userprofile3" width="88" height="70">
      </div>

      <script>
           $(".userprofilepic").draggable({ helper: 'clone'});
      </script>
0

2 Answers 2

1

I'm using jquery UI api to solve drag and drop. Take a look my example and change the style html that you wanted.

HTML

<br><br>

<table class="original" id="diagram">
    <tbody id="sortable2">
   <tr class="new-item"> 
       <td><img src="https://pmcvariety.files.wordpress.com/2016/11/beauty-and-the-beast-trailer.jpg?w=1000&h=563&crop=1" alt="disney" /></td>
   </tr>
    </tbody>
</table>


<br><br>

<table class="clone" id="diagram1" >
    <tbody id="clonetable">

     </tbody>
</table>

 <br><br>   

CSS

table{
    border: 1px solid black;
    width:200px;
}

.original tbody tr.test2 td {
    background: rgba(20, 111, 186, 0.38);
}

img {
  width:200px;
  height:auto;
}

Javascript

$("#clonetable").sortable({
    revert: true,
    stop: function(event, ui) {
    }
});
$(".new-item").draggable({
    connectToSortable: "#clonetable",
    helper: "clone",
    revert: "invalid",
    zIndex: 10000
});

FULL DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much.. your a star ... great pic you have used!! hahaha Disney fan ?
1

Remove # from the div id, modify . to # from the jQuery Code.

3 Comments

Hi Kang-Jun Heo :), thanks ! :) brains half asleep, the clone part still not working :(
@stevenpjm double check it - it should work. Check it again and again. Also try viewing the console window for any error. Make a simple demo to see it working independently. That's called divide to conquer. Your initial mistakes are almost unbelievable. So it's just easy to keep believing that you still have something wrong elsewhere
@stevenpjm try this jsfiddle.net/z6j0s9nx isn't this what you want? You can drag a cloned image of the img (not sure if you want to drag the div or the img, but from your code it is the img).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.