jQuery:如何将元素放在光标下方? [英] jQuery: how do I get the element underneath my cursor?
本文介绍了jQuery:如何将元素放在光标下方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在执行拖放操作,当我将某个元素移到妨碍自己的元素上方时,我希望该元素向下移动.
I'm making a drag and drop action, and I want an element to shift down when I bring an element over the one that is in my way.
推荐答案
一个简单的技巧就是说:
a simple hack would be to say something like:
var hoverElem = null;
$('*').hover(function() {hoverElem = this});
然后,当您需要调用任何函数来获取值时,只需使用hoverElem
then when you need to call what ever function to get the value, just use hoverElem
这是一个资源占用较少的呼叫:
this is a less resource intensive call:
$('*').live('mouseenter', function() { hoverEleme = this; });
由于不建议使用.live(),因此应使用.on()
EDIT 2: due to .live() being deprecated, you should use .on()
$("*").on("mouseenter", function() { hoverElem = this; });
这篇关于jQuery:如何将元素放在光标下方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文