Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Created January 16, 2013 19:00
Show Gist options
  • Save cbmeeks/4549765 to your computer and use it in GitHub Desktop.
Save cbmeeks/4549765 to your computer and use it in GitHub Desktop.
<html>
<body style="margin:0;">
<div id="d" style="background:#ff0;left:200px;position:relative;">
Hello
</div>
</body>
</html>
// document resized to 1503 pixels
document.getElementById('d').getClientRects()[0].width;
// 1303 pixels
// we know it has a "left" of 200 px
// so, 1503 - 1303 yields how many pixels are "off the screen"
// If your margins were 8px, then you would subtract 8px. Because there would be 8 on the left and 8 on the right. But your
// width would then be 1303 - 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment