Adding a delay to droppable event

牧云@^-^@ 提交于 2019-12-24 11:16:39

问题


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();
}; 

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.


回答1:


Something like this maybe?

var globalTimer;

//..
droppable.over = function(event, ui)
{
    globalTimer = setTimeout(function(){node.expand()}, 1000);
},
droppable.out = function(event, ui)
{
    clearTimeout(globalTimer);
};



回答2:


try adding this setTimeout(function () { node.expand() }, 1000);

but I might misunderstood you, do you want the node to appear later or appear only if it stays in the droppable for 1000 ms?



来源:https://stackoverflow.com/questions/11786598/adding-a-delay-to-droppable-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!