Javascript 如何检查鼠标x位置是否在图像中?
我有一个onmouseenter事件,其中我通过jquery选择器$('.imageTile')获得一个图像数组。在Chrome中,我能够这样做,以获得我真正感兴趣的元素的索引:Javascript 如何检查鼠标x位置是否在图像中?,javascript,jquery,asp.net,internet-explorer,mouse-position,Javascript,Jquery,Asp.net,Internet Explorer,Mouse Position,我有一个onmouseenter事件,其中我通过jquery选择器$('.imageTile')获得一个图像数组。在Chrome中,我能够这样做,以获得我真正感兴趣的元素的索引: for(var i = 0; i < $('.imageTile').length; i++) { if(e.y >= $('.imageTile')[i].y && e.y <= $('.imageTile')[i].y + $('.imageTile')[i].height)
for(var i = 0; i < $('.imageTile').length; i++)
{
if(e.y >= $('.imageTile')[i].y && e.y <= $('.imageTile')[i].y + $('.imageTile')[i].height) {
index = i;
break;
}
}
for(var i=0;i<$('.imageTile')。长度;i++)
{
如果(e.y>=$('.imageTile')[i].y&&e.y我认为这会起作用,但我还没有测试它
var index = -1;
$(function(){
$('.imageTile img').hover(function(){
index = $('.imageTile').index($(this));
},
function(){
index = -1; // reset index on mouseout
});
});
你一定很喜欢jQuery,你到底想做什么?可能有一个更简单的方法。你想获取悬停图像的索引吗?$('.imageTile')。on('hover',function(){console.log($(this.index();))
我也希望将X作为某个点,因为我希望在我悬停的图像旁边设置一个图像,最好将顶部设置为相同的位置。