jQuery draggable - 将小图像拖入父级

jQuery draggable - Drag small image inside parent

我有一个图像(小圆圈),我想将其拖到另一个更大的图像(轴)之上。如何将较大的图像设置为包含圆圈的父图像?

下面是我试过的,但是圆不能拖到整个大图上面,只能垂直拖。

代码:

          $(function() {
            $("#draggable").draggable({
              containment: "#container",
              scroll: false
            });
          });
          #draggable {
            position: relative;
            left: 20px;
          }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>


<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Drag a dot</title>

</head>

<body>
  <div id="container">
    <img src="https://ka-perseus-graphie.s3.amazonaws.com/ed9ce4eb0526f1c335eaea9b3a1920232455ec57.png" style="width:304px;height:228px">
    <div id="draggable">
      <img src="http://www.cmjc.ca/images/ferme.png" style="width:15px;height:15px">
    </div>
  </div>
</body>

</html>

#draggable 中删除 position: relative;

以下是我对您的代码所做的一些更改:

HTML

<body>
  <div id="container">
    <div id="draggable" >
      <img src="http://www.cmjc.ca/images/ferme.png">
    </div>
  </div>
</body>

CSS

#draggable { 
  position: absolute;
  left: 142px; 
  top: 160px;
}

#container {
  background: url('https://ka-perseus-graphie.s3.amazonaws.com/ed9ce4eb0526f1c335eaea9b3a1920232455ec57.png'); 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  width: 304px; 
  height: 228px; 
  border: 1px solid black;
}

JS

$(function() {
  $( "#draggable" ).draggable({ containment:'parent' });
});

看到一个example here