gpt4 book ai didi

jquery-ui - 向jQuery可拖动还​​原 “event”添加函数

转载 作者:行者123 更新时间:2023-12-03 11:56:50 24 4
gpt4 key购买 nike

是)我有的:

我有一个可拖动的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)');
}
});

我尝试过的

我尝试使用“还原”作为事件未成功:
revert: function(event, ui) {
$('#peg_icon').css('background-image','url(images/peg-icon-default.png)');
},

我也尝试使用恢复参数来执行此功能:
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;
}
}

内容:

我正在拖动一个div,当它被拖动时,背景图像会更改,而当拖动恢复时,背景图像会恢复为原始状态。

我的问题:

当拖动发生还原时,如何触发CSS更改为另一个元素?

最佳答案

事实证明,还原可以接受一个方法。参见以下完整示例:
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");
}
});
});

希望这对您有帮助...我猜您正在尝试修改的只是问题,而不是尝试在函数调用中使用还原。再次查看您要设置的CSS,并查看是否存在问题。

关于jquery-ui - 向jQuery可拖动还​​原 “event”添加函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14571919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com