let div = document.getElementById("myDiv");
div.addEventListener("click",(event) => {
let pageX = event.pageX, pageY = event.pageY;
if (pageX === undefined){
pageX = event.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft);
}
if(pageY === undefined){
pageY = event.clientY + (document.body.scrollTop || document.documentElement.scrollTop);
}
console. log(` Page coordinates: ${ pageX}, ${ pageY}`);
});
【js工具函数】鼠标事件获取页面坐标(兼容IE)
最新推荐文章于 2022-11-11 20:42:58 发布