Javascript onClick获取第二个元素而不是第一个元素
我已经创建了跟随鼠标的div。现在,每当我单击e.target时,它就等于这个div#moveItem 我不能使用自定义光标,因为宽度将超过128px 有没有办法绕过这个部门,让目标落后Javascript onClick获取第二个元素而不是第一个元素,javascript,html,css,mouseevent,Javascript,Html,Css,Mouseevent,我已经创建了跟随鼠标的div。现在,每当我单击e.target时,它就等于这个div#moveItem 我不能使用自定义光标,因为宽度将超过128px 有没有办法绕过这个部门,让目标落后 var item=document.querySelector(“#moveItem”); var itemRect=item.getBoundingClientRect(); 功能跟随鼠标(e){ var xPos=e.pageX-itemRect.width/2; var yPos=e.pageY-ite
var item=document.querySelector(“#moveItem”);
var itemRect=item.getBoundingClientRect();
功能跟随鼠标(e){
var xPos=e.pageX-itemRect.width/2;
var yPos=e.pageY-itemRect.height/2;
item.style.transform=“translate3d(“+xPos+”px,“+yPos+”px,0)”;
}
功能点击(e){
console.log(如target);
}
document.addEventListener(“mousemove”,followMouse,false);
document.addEventListener(“鼠标向下”,单击,false)代码>
正文{
最小宽度:100%;
最小高度:100%;
}
#移动项目{
宽度:75px;
高度:75px;
背景色:番茄;
位置:绝对位置;
边界半径:50%;
}
跟随鼠标
您正在寻找一个指针事件:无
,以便忽略鼠标后面的div
var item=document.querySelector(“#moveItem”);
var itemRect=item.getBoundingClientRect();
功能跟随鼠标(e){
var xPos=e.pageX-itemRect.width/2;
var yPos=e.pageY-itemRect.height/2;
item.style.transform=“translate3d(“+xPos+”px,“+yPos+”px,0)”;
}
功能点击(e){
console.log(如target);
}
document.addEventListener(“mousemove”,followMouse,false);
document.addEventListener(“鼠标向下”,单击,false)代码>
正文{
最小宽度:100%;
最小高度:100%;
}
#移动项目{
宽度:75px;
高度:75px;
背景色:番茄;
位置:绝对位置;
边界半径:50%;
指针事件:无;
}
跟随鼠标
您正在寻找一个指针事件:无
,以便忽略鼠标后面的div
var item=document.querySelector(“#moveItem”);
var itemRect=item.getBoundingClientRect();
功能跟随鼠标(e){
var xPos=e.pageX-itemRect.width/2;
var yPos=e.pageY-itemRect.height/2;
item.style.transform=“translate3d(“+xPos+”px,“+yPos+”px,0)”;
}
功能点击(e){
console.log(如target);
}
document.addEventListener(“mousemove”,followMouse,false);
document.addEventListener(“鼠标向下”,单击,false)代码>
正文{
最小宽度:100%;
最小高度:100%;
}
#移动项目{
宽度:75px;
高度:75px;
背景色:番茄;
位置:绝对位置;
边界半径:50%;
指针事件:无;
}
跟随鼠标