Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<h2># Plain Text</h2>
<p><span class="target" id="a">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Enim sequi consequatur culpa eum hic aperiam iste minus natus delectus amet quasi assumenda dicta, quis, nihil reiciendis harum rem officia non!</span></p>
  
<h2># With Child Elements</h2>
  
<h3>1. No styles</h3>
<p><span class="target" id="b"><span>Lorem</span> ipsum dolor sit amet, consectetur <span>adipisicing</span> elit. Enim sequi consequatur culpa eum hic <span>aperiam</span> iste minus natus delectus amet quasi <span>assumenda</span> dicta, quis, nihil <span>reiciendis</span> harum rem officia non!</span></p>
  
<h3>2. <code>background-color</code></h3>
<p><span class="target" id="c"><span>Lorem</span> ipsum dolor sit amet, consectetur <span>adipisicing</span> elit. Enim sequi consequatur culpa eum hic <span>aperiam</span> iste minus natus delectus amet quasi <span>assumenda</span> dicta, quis, nihil <span>reiciendis</span> harum rem officia non!</span></p>
<h3>2. <code>opacity</code></h3>
<p><span class="target" id="d"><span>Lorem</span> ipsum dolor sit amet, consectetur <span>adipisicing</span> elit. Enim sequi consequatur culpa eum hic <span>aperiam</span> iste minus natus delectus amet quasi <span>assumenda</span> dicta, quis, nihil <span>reiciendis</span> harum rem officia non!</span></p>
<h3>3. <code>position</code></h3>
<p><span class="target" id="e"><span>Lorem</span> ipsum dolor sit amet, consectetur <span>adipisicing</span> elit. Enim sequi consequatur culpa eum hic <span>aperiam</span> iste minus natus delectus amet quasi <span>assumenda</span> dicta, quis, nihil <span>reiciendis</span> harum rem officia non!</span></p>
<h3>4. <code>border</code></h3>
<p><span class="target" id="f"><span>Lorem</span> ipsum dolor sit amet, consectetur <span>adipisicing</span> elit. Enim sequi consequatur culpa eum hic <span>aperiam</span> iste minus natus delectus amet quasi <span>assumenda</span> dicta, quis, nihil <span>reiciendis</span> harum rem officia non!</span></p>
<h3>5. <code>padding</code></h3>
<p><span class="target" id="g"><span>Lorem</span> ipsum dolor sit amet, consectetur <span>adipisicing</span> elit. Enim sequi consequatur culpa eum hic <span>aperiam</span> iste minus natus delectus amet quasi <span>assumenda</span> dicta, quis, nihil <span>reiciendis</span> harum rem officia non!</span></p>
<h3>6. <code>padding</code></h3>
<p><span class="target" id="h"><span>Lorem</span> ipsum dolor sit amet, consectetur <span>adipisicing</span> elit. Enim sequi consequatur culpa eum hic <span>aperiam</span> iste minus natus delectus amet quasi <span>assumenda</span> dicta, quis, nihil <span>reiciendis</span> harum rem officia non!</span></p>
</body>
</html>
 
$('.target').each(function () {
  addClientRectsOverlay(this);
});
function addClientRectsOverlay(elt) {
    // Absolutely position a div over each client rect so that its border width
    // is the same as the rectangle's width.
    // Note: the overlays will be out of place if the user resizes or zooms.
    var rects = elt.getClientRects();
    for (var i = 0; i != rects.length; i++) {
        var rect = rects[i];
        var tableRectDiv = document.createElement('div');
        tableRectDiv.style.position = 'absolute';
        tableRectDiv.style.border = '1px solid #69c';
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
        tableRectDiv.style.margin = tableRectDiv.style.padding = '0';
        tableRectDiv.style.top = (rect.top + scrollTop) + 'px';
        tableRectDiv.style.left = (rect.left + scrollLeft) + 'px';
        // we want rect.width to be the border width, so content width is 2px less.
        tableRectDiv.style.width = rect.width + 'px';
        tableRectDiv.style.height = rect.height + 'px';
        tableRectDiv.style.pointerEvents = 'none';
        document.body.appendChild(tableRectDiv);
    }
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers