我理解jQuery Ui的逻辑,我已经成功地创建了拖放。但是,我在尝试检查按下按钮上是否有拖动时遇到问题。这是我想要实现的一些伪代码
function checkAnswers(){ (called on button press)
If(Drag 2 is on Drop 1){
(Drag 2).css('color', 'green')
}
If(Drag 3 or Drag 4 is on Drop 1){
(Drag 3/4).css('color', 'red')
}
道歉忘了提到这是javascript
答案 0 :(得分:2)
您可以安排这样的事情:
$("#draggable").draggable();
$("#droppable").droppable({
drop: function () {
alert("dropped");
},
over: function () {
$( "#droppable" ).droppable( "option", "hoverClass", "drop-hover" );
},
out: function () {
$( "#droppable" ).droppable( "option", "hoverClass", "" );
},
hoverClass: "drop-hover"
});
$("#btn").click( function () {
var hoverClass = $("#droppable").droppable( "option", "hoverClass" );
console.log(hoverClass);
if(hoverClass === 'drop-hover') {
console.log("hovered");
} else {
console.log("not hovered");
}
});