jQuery UI droppable:悬停时调整元素大小不起作用
我有一个 jQuery UI 可放置元素,当可拖动元素悬停在其上方时,我希望该元素变得更大。我尝试过使用hoverClass选项并绑定到drophover事件。
从视觉上看,这两种方法都效果很好。然而,一旦可拖动退出可放置的原始(较小)边界,jQuery UI 会将其解释为“退出”,尽管仍位于当前(较大)边界内。
例如,js:
$("#dropable").droppable({
hoverClass: 'hovering'
}.bind('dropout', function () {console.log('dropout')});
css:
#droppable { background: teal; height: 10px; }
#droppable.hovering { height: 200px; }
在这种情况下,当可拖动对象悬停在可放置对象上时,可放置对象的尺寸在视觉上会增加到 200 像素。如果此时,可拖动对象向下移动 20px,我预计它仍然悬停在可放置对象上。相反,jQuery UI 会触发 dropout 事件,并且 droppable 恢复为 10px 高。
有人知道如何让它按照我期望的方式运行吗?
jsFiddle 示例: http://jsfiddle.net/kWFb9/
I have a jQuery UI droppable element which I would like to get bigger when a draggable is hovered over it. I have tried both using the hoverClass option and also binding to the drophover event.
Visually, both these methods work fine. However, once the draggable exits the original (smaller) boundary of the droppable, jQuery UI interprets this as a 'dropout', despite still being within the current (larger) boundary.
For example, js:
$("#dropable").droppable({
hoverClass: 'hovering'
}.bind('dropout', function () {console.log('dropout')});
css:
#droppable { background: teal; height: 10px; }
#droppable.hovering { height: 200px; }
In this case, when a draggable hovers over the droppable, the droppable visually increases in size to 200px. If at this point, the draggable is moved down by 20px, I would expect it to still be hovering over the droppable. Instead, jQuery UI fires the dropout event and the droppable reverts to being 10px high.
Anyone know how to get it to behave in the way I'd expect it to?
jsFiddle example: http://jsfiddle.net/kWFb9/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
遇到了同样的问题,我能够通过使用以下选项来解决它:
这是工作小提琴: http:// jsfiddle.net/kWFb9/51/
请参阅http://bugs.jqueryui.com/ticket/2970
Had the same problem, I was able to solve it by using the following options:
Here's the working fiddle: http://jsfiddle.net/kWFb9/51/
See http://bugs.jqueryui.com/ticket/2970
所以我对你的小提琴做了一些调整,
首先我将可放置容差设置为“触摸”,每当可拖动的任何部分触摸它时就会激活它。这会导致应用悬停类。
接下来,我添加了一个动画来稍微调整可拖动元素的大小。我不确定这是否是您想要的功能,所以我还是把它放在那里。
最后,当可拖动元素放入可放置区域时,我将悬停类永久应用于可放置元素。 时,可放置元素不会恢复到那么窄的高度
这样,当其中有元素http://jsfiddle.net /kWFb9/2/
编辑:
更好的小提琴:http://jsfiddle.net/kWFb9/6/
我希望这有帮助:)
So I made a couple tweaks to your fiddle
First I set the droppable tolerance to "touch" which will activate whenever any part of the draggable is touching it. This causes the hovering class to be applied.
Next I added an animation to resize your draggable element slightly. I wasn't sure if this was functionality you wanted or not so I put it in there anyways.
Lastly, I permanently apply the hovering class to the droppable element when the draggable element is dropped into the droppable zone. This way the droppable doesn't revert to that narrow height when there is an element in it
http://jsfiddle.net/kWFb9/2/
EDIT:
Better fiddle: http://jsfiddle.net/kWFb9/6/
I hope this helps :)
您可以创建一个更大的(即 #droppable.hovering 的大小)没有背景的
div
并将您的 droppable 应用于它。请注意,您没有提供 HTML,但新的#drop_container
应包含这两个 div。JS
CSS
或者您可以尝试使用 这篇文章
[编辑]我已经编辑了我的代码,这是一个jsfiddle:http://jsfiddle.net/94Qyc/1/
我必须使用全局变量,但我没有找到更好的方法来检查盒子是否掉落。如果有人有想法,那就太好了。
you could create a bigger (i.e. the size of #droppable.hovering)
div
without background and apply your droppable to it. Note that you didn't provide HTML but the new#drop_container
should contain both divs.JS
CSS
Or you could try another solution with
.live()
or.livequery()
from this article[EDIT] I've edited my code and here is a jsfiddle: http://jsfiddle.net/94Qyc/1/
I had to use a global var, I didn't find a better way to check wether the box was dropped. If anybody has an idea, that would be great.
还有另一个(哼哼)不错的解决方案:
TL;DR: Fiddle
问题是插件在创建小部件时存储 dom 元素的大小值(类似):
并且小部件的偏移量在 $.ui.ddmanager.prepareOffsets(); 中初始化;
所以我们只需要覆盖proportions对象即可。
这样允许访问真实的插件属性,因此我们可以编写如下内容:
There is an other (hum hum) not bad solution :
TL;DR: Fiddle
The problem is that the plugin stores dom element's size values when the widget is created (something like) :
And the offset for widgets are initialized in $.ui.ddmanager.prepareOffsets();
So we only need to overwrite the proportions object.
This way allow to access to real plugin properties so we can write something like :