jQuery get光标所在的元素 [英] jquery get element where the cursor is
问题描述
我正在使用javascript和jquery为我的网站构建一个splittesting工具.现在,我想显示每个元素,当光标经过预览框中的元素时,我想对它进行拆分测试.有可能做这样的事情吗?我整理这样的东西
I'm building a splittesting tool for my website with javascript and jquery. Now I want to show for each elements I want to splittest a little hovermenu when the cursor passes over the element in my previewbox. Is there any possibility to do something like this ? I treid something like this
$('body').hover(function(event){
console.log(event.target.nodeName);
// to see if it's showing up the element
});
,但仅触发一次.因为我不想使用click,因为我也想在锚元素上显示菜单,所以我有点迷路了
but it's only triggering once. As I don't want to use click since I want also to showup the menu on anchor elements I'm a bit lost
推荐答案
我相信您要在此处使用mousemove
事件而不是hover
事件.
I believe you want to use the mousemove
event here instead of the hover
event.
$('body').mousemove(function(evt){
console.log(evt.target);
});
请记住要特别小心地使用mousemove
.
Just remember to use mousemove
with extreme caution.
这篇关于jQuery get光标所在的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!