获得鼠标指向的页面元素 发表于 2020-11-12 | 分类于 前端 | 本文总阅读量 次 类F12鼠标选中功能12345678910111213141516171819202122232425window.onmousemove = track_mouse;var last_element = nullfunction track_mouse(event){ var elementMouseIsOver = get_current_element(event) if (elementMouseIsOver === last_element) { return; } if (last_element != null) { remove_hightlight(last_element); } highlight(elementMouseIsOver); last_element = elementMouseIsOver;}function get_current_element(event){ var x = event.clientX; var y = event.clientY; var element = document.elementFromPoint(x, y); return element;}function highlight(element){ element.style.outline = '#f00 solid 2px';}function remove_hightlight(element){ element.style.removeProperty('outline');}