Nik*_*pal 13 jquery jquery-ui droppable draggable
如果ajax调用on drop返回失败,我希望draggable恢复到其原始位置.这是我想象的代码..如果在ajax调用正在进行中,draggable可以放在droppable中,这是可以的...
<script type="text/javascript">
jQuery(document).ready($){
$("#dragMe").draggable();
$("#dropHere").droppable({
drop: function(){
// make ajax call here. check if it returns success.
// make draggable to return to its old position on failure.
}
});
}
</script>
<div id="dragMe">DragMe</div>
<div id="dropHere">DropHere</div>
Run Code Online (Sandbox Code Playgroud)
Nik*_*pal 18
感谢您的重播@Fran Verona.
我这样解决了:
<script type="text/javascript">
jQuery(document).ready($){
$("#dragMe").draggable({
start: function(){
$(this).data("origPosition",$(this).position());
}
});
$("#dropHere").droppable({
drop: function(){
//make ajax call or whatever validation here. check if it returns success.
//returns result = true/false for success/failure;
if(!result){ //failed
ui.draggable.animate(ui.draggable.data().origPosition,"slow");
return;
}
//handling for success..
}
});
}
</script>
<div id="dragMe">DragMe</div>
<div id="dropHere">DropHere</div>
Run Code Online (Sandbox Code Playgroud)
想要避免任何新的全局变量,变量的数量也是不可预测的,因为在第一次正在进行时,即在第一次调用返回之前,可能会发生许多拖放.顺便说一句,对于任何寻找相同答案的人来说,.data()并不适用于所有元素,但我不确定jQuery.data(),但是如果有人发现任何错误,请告诉我!:)
| 归档时间: |
|
| 查看次数: |
7732 次 |
| 最近记录: |