Skip to content

Instantly share code, notes, and snippets.

@Dev1an
Last active April 27, 2017 12:07
Show Gist options
  • Save Dev1an/821531ef3efe24fc6607400e52167342 to your computer and use it in GitHub Desktop.
Save Dev1an/821531ef3efe24fc6607400e52167342 to your computer and use it in GitHub Desktop.
function highlight(highlightedElement) {
var restore = []
const oldRadius = highlightedElement.style.borderRadius
const oldShadow = highlightedElement.style.boxShadow
restore.push(() => {highlightedElement.style.borderRadius = oldRadius; highlightedElement.style.boxShadow = oldShadow})
highlightedElement.style.borderRadius = "1px"
highlightedElement.style.boxShadow = "0 0 0 4px white , 2px 2px 10px 4px rgba(0, 0, 0, 0.39)"
const timer = setTimeout(function() {
var element = highlightedElement
var parent = element.parentNode
while (parent != null) {
for (let sibling of parent.childNodes) {
if (sibling != element && sibling instanceof HTMLElement) {
const oldFilter = sibling.style.filter
restore.push(() => {sibling.style.filter = oldFilter;})
sibling.style.filter += " blur(5px)"
}
}
element = parent
parent = element.parentNode
}
}, 2000);
restore.push(()=> clearTimeout(timer) )
return () => restore.forEach(f=>f())
}
let removePreviousHighlight = () => {};
document.body.addEventListener('mouseover', mouseOver);
function mouseOver(event) {
removePreviousHighlight();
removePreviousHighlight = highlight(event.target);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment