Mouseover Highlighting of Page Elements

旧巷老猫 提交于 2019-12-12 01:04:38

问题


I am looking for either an open source solution already available or for someone to point me in the right direction to find this. I am creating a Firefox extension that works for elements from the DOM. In Firefox and Chrome, there are element inspectors that highlight the region and/or element that your mouse is currently hovering over, such as the div it is currently hovered over or a button if it is hovered over that. I'm looking for how to implement that functionality into my own extension. Let me know if there are any solutions to this, thanks!


回答1:


try something like this:

var lastBoxedEl;

function moused(e) {
    var target = e.target; //experiment, try e.currentTarget, e.originanalTarget
    if (lastBoxedEl) {
        lastBoxedEl.style.outline = 'none'
    }
    lastBoxedEl = target;
    target.style.outline = '5px solid red';
}
document.body.addEventListener('mouseover', moused, false);



回答2:


I did something in the past for a demo. Here is the source opened for your request:

https://github.com/kashiif/hilight-dom-element-on-hover

Note that this is not complete and may require finishing e.g.:

  1. The red box is left behind after the element is clicked.
  2. There is a little re-flow of element because a border is being added. You may modify the box class such that box-sizing is set to border-box

If you like you may send me a pull request of the changes.



来源:https://stackoverflow.com/questions/21586572/mouseover-highlighting-of-page-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!