有没有办法创建一个重置按钮,它将所有可放置/可拖动的元素返回到它们的原始位置?
我正在使用以下 javascript,该 javascript 是从此处的先前答案修改而来的。
$(window).load(function(){var counter = 0;
$(".draggable").draggable({ cursor: "move", revert: "invalid"});
$(".drop").droppable({ accept: ".draggable",
drop: function(event, ui) {
console.log("drop");
$(this).removeClass("border").removeClass("over");
var dropped = ui.draggable;
var droppedOn = $(this);
$(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn);
counter ++;
if (counter > 0 ) {
$(".hidden").removeClass().addClass("visible");
}
},
over: function(event, elem) {
$(this).addClass("over");
console.log("over");
}
,
out: function(event, elem) {
$(this).removeClass("over");
counter --;
}
});
$(".start").droppable({ accept: ".draggable", drop: function(event, ui) {
console.log("drop");
$(this).removeClass("border").removeClass("over");
var dropped = ui.draggable;
var droppedOn = $(this);
$(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn);
counter --;
if (counter < 1 ) {
$(".visible").removeClass().addClass("hidden");
}
}});
})(jQuery);
这是我的 HTML
<div class="row">
<div class="large-8 columns">
<div class="start">
<img src="http://placehold.it/140x100" id="one" title="one" class="draggable ui-widget-content" />
<img src="http://placehold.it/150x100" id="two" title="two" class="draggable ui-widget-content" />
</div>
</div>
<div class="large-4 columns">
<div class="drop">
</div>
<div class="large-1 columns">
<input type="submit" value="generate report" class="hidden" />
<input type="reset" value="reset" class="reset" />
</div>
</div>
</div>