Dom*_*vus 21 jquery-ui revert jquery-draggable
我有一个可拖动的div,其恢复参数设置为"无效".
当恢复发生时,我想触发CSS更改到另一个元素.
"revert"是参数而不是事件,因此在恢复发生时触发所需的CSS更改时遇到很大困难.
$('#peg_icon').draggable({
revert: 'invalid',
scroll: false,
stack: "#peg_icon",
drag: function(event, ui) {
$('#peg_icon').css('background-image','url(images/peg-icon-when-dragged.png)');
}
});
Run Code Online (Sandbox Code Playgroud)
我没有尝试使用"revert"作为事件:
revert: function(event, ui) {
$('#peg_icon').css('background-image','url(images/peg-icon-default.png)');
},
Run Code Online (Sandbox Code Playgroud)
我也无意中试图让revert paramater接受这个功能:
function(socketObj)
{
//if false then no socket object drop occurred.
if(socketObj === false)
{
//revert the peg by returning true
$('#peg_icon').css('background-image','url(images/peg-icon-default.png)');
return true;
}
else
{
//return false so that the peg does not revert
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在拖动一个div,当拖动时,背景图像会改变,当拖动恢复时,背景图像将恢复到其原始状态.
在拖动时发生恢复时,如何触发对其他元素的CSS更改?
Jas*_*lor 20
事实证明,revert可以接受一种方法.请参阅此示例以获取完整示例:http: //jsfiddle.net/mori57/Xpscw/
特别:
$(function() {
$("#ducky").draggable({
revert: function(is_valid_drop){
console.log("is_valid_drop = " + is_valid_drop);
// when you're done, you need to remove the "dragging" class
// and yes, I'm sure this can be refactored better, but I'm
// out of time for today! :)
if(!is_valid_drop){
console.log("revert triggered");
$(".pond").addClass("green");
$(this).removeClass("inmotion");
return true;
} else {
$(".pond").removeClass("green");
$(this).removeClass("inmotion");
}
},
drag: function(){
// as you drag, add your "dragging" class, like so:
$(this).addClass("inmotion");
}
});
$("#boat").droppable({
drop: function( event, ui ) {
$(this)
.addClass("ui-state-highlight");
}
});
});
Run Code Online (Sandbox Code Playgroud)
希望这有帮助...我猜你无论你想修改什么都是问题,而不是尝试使用函数调用恢复.再看一下你想要设置的CSS,看看你的问题是否存在.