Skip to content

Instantly share code, notes, and snippets.

@jackyef
Created June 16, 2020 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackyef/cc1f2229e5f54a56cea59293de98e7f4 to your computer and use it in GitHub Desktop.
Save jackyef/cc1f2229e5f54a56cea59293de98e7f4 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="id">
<body>
<h1 id="LCP">Heading 1</h1>
<script>
const lcpElement = document.getElementById("LCP");
const rect = lcpElement.getBoundingClientRect();
console.log('initial', JSON.stringify({ rect }, null, 2));
console.log(`Initial size ${rect.width}px + ${rect.height}px`);
console.log(`Initial padding ${rect.top}px + ${rect.left}px`);
</script>
<script>
const lcpElement2 = document.getElementById("LCP");
var ro = new ResizeObserver(entries => {
console.log('resize happened, wtf');
for (let entry of entries) {
const cr = entry.contentRect;
console.log('resized', JSON.stringify({ cr }, null, 2));
console.log(`Element size: ${cr.width}px x ${cr.height}px`);
console.log(`Element padding: ${cr.top}px ; ${cr.left}px`);
console.log({ entry })
}
});
// Observe one or multiple elements
ro.observe(lcpElement2);
</script>
<script id="jsbin-source-html" type="text/html">
<!DOCTYPE html>
<html lang="id">
<body>
<h1 id="LCP">Heading 1</h1>
<script>
const lcpElement = document.getElementById("LCP");
const rect = lcpElement.getBoundingClientRect();
console.log('initial', JSON.stringify({ rect }, null, 2));
console.log(`Initial size ${rect.width}px + ${rect.height}px`);
console.log(`Initial padding ${rect.top}px + ${rect.left}px`);
<\/script>
<script>
const lcpElement2 = document.getElementById("LCP");
var ro = new ResizeObserver(entries => {
console.log('resize happened, wtf');
for (let entry of entries) {
const cr = entry.contentRect;
console.log('resized', JSON.stringify({ cr }, null, 2));
console.log(`Element size: ${cr.width}px x ${cr.height}px`);
console.log(`Element padding: ${cr.top}px ; ${cr.left}px`);
console.log({ entry })
}
});
// Observe one or multiple elements
ro.observe(lcpElement2);
<\/script>
</body>
</html>
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment