问题描述
我有一个带有dropover事件处理程序的droppable元素.将元素拖动到可放置对象上方将展开一个节点.但是,我想添加一个延迟,以使节点不会立即展开,即在展开之前,您必须将可拖动对象放在可放置对象上一秒钟.
I have a droppable element with a dropover event handler. Dragging an element over the droppable expands a node. However, I want to add a delay so the node does not expand immediately, i.e. you have to hold the draggable over the droppable for a second before it expands.
droppable.over = function(event, ui) {
// expand node if dragover lasts 1000 milliseconds
node.expand();
};
我的第一个想法是仅在node.expand()
上使用setTimeout
,但这并不能满足我的要求,它只是延迟了节点的扩展.看起来我没有可以设置的任何配置来实现此目的,所以我想知道如何做到这一点.
My first thought was to simply use setTimeout
on node.expand()
, but this doesn't do what I want, it simply delays the node expanding. It doesn't look like there's any configuration I can set to achieve this, so I'm wondering how I can do it.
推荐答案
像这样的事情?
var globalTimer;
//..
droppable.over = function(event, ui)
{
globalTimer = setTimeout(function(){node.expand()}, 1000);
},
droppable.out = function(event, ui)
{
clearTimeout(globalTimer);
};
这篇关于为可投放事件添加延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!