鼠标按下时是否可以更改可拖动元素的 z-Index?
我发现JQuery UI Draggable
的stack选项
非常有用,但它只有在拖动元素时才起作用。那么,我可以更改stack值< /code> 当我
**单击元素**
或使用 mousedown 事件
时可拖动的元素?
非常感谢~~!!
可拖动插件更改可拖动元素堆栈[z-index]顺序的方式是拖动和移动元素。如果您只单击可拖动元素,它不会更改堆栈顺序。而且我希望它在我时改变单击。
I found that the stack option
of JQuery UI draggable
was very useful , but it only work when I dragging the elements .So, can I change the stack value
of elements which draggable just when I **click the elements**
or with the mousedown event
??
Thank you very much~~!!
The way the draggable plugin to change draggable elements stack[z-index] order is dragging and moving the element.If you only click the draggable element it doesn't change the stack order.And I want it to change when I click.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这不适合你吗?
Is this not working for you?
注意请参阅我对您的问题的评论,我认为我两次在下面写下我都误解了它。
如果您希望确保拖动过程中拖动的项目始终高于其他所有项目,则可以在与您的可拖动对象匹配的选择器中设置
z-index
代码>ui-draggable-dragging。 jQuery UI 将该类添加到拖动操作期间被拖动的元素中。例如,假设您正在拖动名为
foo
的 div 内的跨度。 CSS 将为:Live example
由于该类仅在拖动期间添加,因此z -index
值仅在拖动过程中生效。请参阅文档中的“概述”。编辑: ...通过使用
zIndex
选项 (实例)。Note See my comment on your question, I think both times I was writing the below I misunderstood it.
If you're looking to ensure that the item you're dragging is always above everything else during the drag, you can set the
z-index
in a selector matching your draggable with the classui-draggable-dragging
. jQuery UI adds that class to the element being dragged during the drag operation.So for instance, let's say you're dragging spans that are inside a div called
foo
. The CSS would be:Live example
Since the class is only added during the drag, thatz-index
value will only take effect during the drag. See the "overview" in the docs.Edit: ...by using the
zIndex
option (live example).您可以将以下代码放在可拖动插件(jsfiddle)之后:
或者,您可能想要将其制作为到一个单独的选项中,如下所示(jsfiddle):
You might place the following code after the draggable plugin (jsfiddle):
Or, you might want to make it into a separate option as follows (jsfiddle):
由于我在搜索时发现了这个问题,所以我想我会发布我找到的答案。单击不会更改 z-index 的原因是拖动尚未开始。要强制在所有单击时启动拖动,请将距离选项设置为 0:
http:// /docs.jquery.com/UI/Draggable#option-distance
该行为与默认行为几乎相同,只是现在即使没有鼠标移动,z 顺序也会发生变化。
Since I found this question when I was searching, I figured I would post the answer I found. The reason a click does not change the z-index is that the drag hasn't initiated yet. To force the drag to be initiated on all clicks, set the distance option to 0:
http://docs.jquery.com/UI/Draggable#option-distance
The behavior is nearly the same as the default, except now z-order changes even with no mouse motion.