Created
October 24, 2016 18:47
-
-
Save doup/07654547379b3bdb4098b98e77986291 to your computer and use it in GitHub Desktop.
Chrome/Firefox element inspects element detection & bounding box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Inspector</title> | |
<meta name="description" content="The HTML5 Herald"> | |
<meta name="author" content="SitePoint"> | |
<style> | |
body { | |
width: 50%; | |
margin: 0 auto; | |
} | |
</style> | |
<!--<link rel="stylesheet" href="css/styles.css?v=1.0">--> | |
<!--[if lt IE 9]> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script> | |
<![endif]--> | |
</head> | |
<body> | |
<header> | |
<h1>Prueba</h1> | |
</header> | |
<main> | |
<p style='padding: 40px; border-top: 5px solid #f00; margin-top: 20px; margin-bottom: 20px;'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
</main> | |
<footer> | |
<p style='margin-left: 20px;'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
</footer> | |
<script> | |
var last = null; | |
var box = document.createElement('div'); | |
box.innerHTML = ''; | |
box.style.display = 'none'; | |
box.style.backgroundColor = 'rgba(255, 0, 0, 0.3)'; | |
box.style.pointerEvents = 'none'; | |
box.style.position = 'absolute'; | |
document.body.appendChild(box); | |
document.addEventListener('mousemove', function (e) { | |
var el = document.elementFromPoint(e.pageX, e.pageY); | |
if (el.tagName == 'BODY' || el.tagName == 'HTML') { | |
box.style.display = 'none'; | |
last = null; | |
return; | |
} | |
if (last !== el) { | |
last = el; | |
var bbox = el.getBoundingClientRect(); | |
box.style.display = 'block'; | |
box.style.top = bbox.top +'px'; | |
box.style.left = bbox.left +'px'; | |
box.style.width = bbox.width +'px'; | |
box.style.height = bbox.height +'px'; | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment