一个简单的拖放操作,三个可放置的div每个只接受一个可拖动的元素。在chrome和safari中工作,但是在firefox中,当我拖动第二个元素时,droppable元素在页面上移动。简单的html和bootstrap容器都会发生这种情况,所以我认为问题出在jquery中,但我看不出它是什么。非常感谢任何帮助。
jQuery(function ($) {
$(".rect").draggable({revert: 'invalid', snap: ".dropSnap",
stack: ".draggable"} );
$("#simpleregular").droppable({
accept: "#reg",
//accept: "#cars",
drop: function (event, ui) {
$(this).css("background-color", "lightgreen");
ui.draggable.position( { of: $(this), my: 'middle bottom', at: 'middle bottom' } );
},
out: function (event, ui) {
$(this).css("background-color", "")
}
});
$("#presentcontinuous").droppable({
accept: "#cont",
drop: function (event, ui) {
$(this).css("background-color", "lightgreen");
ui.draggable.position( { of: $(this), my: 'middle bottom', at: 'middle bottom' } );
},
out: function (event, ui) {
$(this).css("background-color", "")
}
});
$("#simplegeneral").droppable({
accept: "#gen",
drop: function (event, ui) {
$(this).css("background-color", "lightgreen");
ui.draggable.position( { of: $(this), my: 'middle bottom', at: 'middle bottom' } );
},
out: function (event, ui) {
$(this).css("background-color", "")
}
});
});
<link rel="stylesheet" href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"/>
<script type="text/javascript" src="https://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript" src="https://www.pureexample.com/js/lib/jquery.ui.touch-punch.min.js"></script>
<div>
<div>
<div id="cont" class="rect"><img src="../images/sentence_present_continuous.png" alt="present continuous"></div>
</div>
<div>
<div id="reg" class="rect"><img src="../images/sentence_simple_regular.png"></div>
</div>
<div>
<div id="gen" class="rect"><img src="../images/sentence_simple_general.png"></div>
</div>
</div>
<br>
<div>
<div>
<div id="presentcontinuous" class="squaredotted"><img src="../images/present_continuous.png" alt="present continuous"></div>
<div id="continuous"></div>
</div>
<div>
<div id="simpleregular" class="squaredotted"><img src="../images/simple_present_regular.png" alt="simple regular"></div>
<div id="regular"></div>
</div>
<div>
<div id="simplegeneral" class="squaredotted"><img src="../images/simple_present_general.png" alt="simple general"></div>
<div id="general"></div>
</div>
</div>
#container {
margin-left: 50px;
margin-right: 20px;
margin-top: 55px;
}
.navbar {
background: rgba(0, 0, 0, 0.7);
/*background: transparent; */
border-color: black;
color: #FFFFFF;
}
.active {
background: rgba(211, 211, 211, 0.7);
}
.active a {
color: black;
}
.navbar-default a {
color: #ffffff;
}
#navDiv {
background: rgba(61, 61, 61, 0.5);
background: transparent;
border-color: transparent;
}
#navDiv a {
background: rgba(61, 61, 61, 0.5);
background: transparent;
border-color: transparent;
color: white;
}
#navDiv a:hover {
color: #4DBBDB;
}
#navDiv a:active {
color: blue;
}
.menu ul li a {
padding: 20px;
background: rgba(4, 1, 7, 0.5);
text-decoration: none;
font: bold 14px Helvetica, Sans-Serif;
letter-spacing: -1px;
color: white;
}
/*text-shadow: #eee 0px 0px 2px; } */
.menu ul li a:hover {
-moz-box-shadow: 0 -5px 10px #756377;
-webkit-box-shadow: 0 -5px 10px #777;
padding: 20px;
background: rgba(255, 255, 255, 0.24);
text-decoration: none;
font: bold 14px Helvetica, Sans-Serif;
letter-spacing: -1px;
color: white;
}
hr {
display: block;
}
.reveal {
display: none;
background-color: #E6E6E6;
}
span.highlighted {
background-color: pink;
}
span.highlighted2 {
background-color: blueviolet;
color: white;
}
span.highlighted3 {
background-color: cyan;
}
span.highlighted4 {
background-color: dimgrey;
color: white;
}
.peekaboo {
visibility: hidden;
}
.answer {
color: green;
}
.leftPanel {
margin-left: 10px;
}
.rightPanel {
margin-left: 50px;
}
#header {
text-align: center;
/*background-color: #9999FF;*/
margin-right: 10px;
color: white;
}
.header {
margin-top: 20px;
}
#btn {
background-color: #0f0f0f;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
color: white; /*Sets the text hover color on navbar*/
}
.nav .navbar-nav > li > a:link, .navbar-default .navbar-nav > li > a:link {
color: white; /*Sets the text color on navbar*/
}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active >
a:hover, .navbar-default .navbar-nav > .active > a:focus {
color: black; /*BACKGROUND color for active*/
}
.navbar-brand > i > a:hover, .navbar-brand .navbar-brand > li > a:focus {
color: white; /*Sets the text hover color on navbar*/
}
.whitelink a:link {
color: white;
}
span.glyphicon-circle-arrow-right {
font-size: 2.5em;
}
span.glyphicon-info-sign {
font-size: 2.5em;
}
span.glyphicon-circle-arrow-left {
font-size: 2.5em;
}
span.glyphicon-facetime-video {
font-size: 2.5em;
}
span.glyphicon-headphones {
font-size: 2.5em;
}
span.glyphicon-arrow-down {
font-size: 2.5em;
}
span.glyphicon-question-sign {
font-size: 2.5em;
}
span.glyphicon-tasks {
font-size: 2.5em;
}
span.glyphicon-thumbs-up {
font-size: 2.5em;
}
span.glyphicon-education {
font-size: 2.5em;
}
span.glyphicon-random {
font-size: 2.5em;
}
span.glyphicon-sort {
font-size: 2.5em;
}
span.glyphicon-pencil {
font-size: 2.5em;
}
span.glyphicon-thumbs-up small {
font-size: 5em;
}
.small {
font-size: 1em !important;;
}
.list-group-item {
border: 0;
}
.list-group-item a {
color: #333333;
}
.list-group-item a:hover {
color: #4DBBDB;
}
.gap {
font-weight: bold;
}
#vocab {
background-color: #E6E6E6;
border: 1px solid black;
padding-left: 10px;
}
.vid {
margin-top: 10px;
}
.truefalse {
text-align: left;
}
#pics {
width: 750px;
}
#sentences {
width: 750px;
}
.sortable-list2 {
list-style-type: none;
margin: 0 auto;
padding: 0;
width: 100px;
}
#sortable-list2 li {
margin: 0 auto;
padding: 1px;
float: left;
width: 120px;
height: 120px;
font-size: 2em;
font-weight: bold;
text-align: center;
background-color: white;
}
#sortable-list1 {
list-style-type: none;
margin: 0 auto;
padding: 0;
width: 600px;
}
#sortable-list1 li {
margin: 3px 3px 3px 0;
padding: 1px;
float: left;
width: 120px;
height: 120px;
font-size: 1em;
text-align: center;
}
#image-list1 {
list-style-type: none;
margin: 0 auto;
padding: 0;
width: 600px;
}
#image-list1 li {
margin: 3px 3px 3px 0;
padding: 1px;
float: left;
width: 110px;
height: 120px;
font-size: 4em;
text-align: center;
background-color: white;
}
#image-list2 {
list-style-type: none;
margin: 0 auto;
padding: 0;
width: 600px;
}
#image-list2 li {
margin: 3px 3px 3px 0;
padding: 1px;
float: left;
width: 110px;
height: 120px;
font-size: 1em;
font-weight: bold;
text-align: center;
background-color: white;
}
.toggler {
width: 500px;
height: 200px;
}
#button {
padding: .5em 1em;
text-decoration: none;
}
#effect {
width: 240px;
height: 135px;
padding: 0.4em;
position: relative;
}
#effect h3 {
margin: 0;
padding: 0.4em;
text-align: center;
}
audio {
display: table;
margin: 0 auto;
}
iframe {
border: 0px;
}
#sentences {
border: 1px solid black;
width: 600px;
}
#pics {
border: 1px solid black;
width: 600px;
}
#vocab {
display:none;
}
.bold {
font-weight: bold;
}
.underline {
text-decoration: underline;
}
.words {
text-align: center;
}
#score {
background-color: #E6E6E6;
/*border: 1px solid;*/
}
.black {
background-color: black;
}
.inverse-dropdown {
background-color: #222;
border-color: #080808;
}
li a {
color: #999;
}
a hover{
color: #fff;
background-color: #000;
}
.rect {
width: 260px;
height: 63px;
border: 1px solid black;
margin-bottom: 0px;
margin-left: 0px;
margin-top: 0px;
text-align: center;
line-height: 100px;
float: left;
background-color: white;
cursor: pointer;
z-index: 10000;
}
.squaredotted {
width: 260px;
height: 275px;
border: 1px dotted gray;
margin-bottom: 5px;
margin-left: 5px;
text-align: center;
line-height: 150px;
float: left;
background-color: lightgray;
}
.squaredotted img {
vertical-align: bottom;
}
答案 0 :(得分:0)
所以经过一些实验和一些谷歌搜索后,我发现不是把可拖动的东西放在div中,而是使用列表项并将droppables留在div中。我猜有些浏览器只是更宽容。可拖动现在看起来像:
<ul>
<li id="cont" class="rect"><img src="../../images/sentence_present_continuous.png" alt="present continuous"></li>
<li id="reg" class="rect"><img src="../../images/sentence_simple_regular.png"></li>
<li id="gen" class="rect"><img src="../../images/sentence_simple_general.png"></li>
</ul>
完成工作