Skip to content

Instantly share code, notes, and snippets.

@developit
Created December 12, 2016 19:54
Show Gist options
  • Select an option

  • Save developit/fb4676468c3ae22beea15018b3dde49b to your computer and use it in GitHub Desktop.

Select an option

Save developit/fb4676468c3ae22beea15018b3dde49b to your computer and use it in GitHub Desktop.
paste this into any preact app
[].filter.call(document.querySelectorAll('*'), el => {
if (el._component) {
var p = el._priority = el.offsetHeight ? (1 - el.getBoundingClientRect().top/window.innerHeight) : -1;
if (p>0) {
el.setAttribute('data-priority', p);
return true;
}
}
});
var style = document.createElement('style');
style.appendChild(document.createTextNode(`
[data-priority] {
position: relative;
}
[data-priority]::before {
content:attr(data-priority);
position:absolute; left:0; top:0; padding:3px;
background:orange; color:white;
font-size: 11px; line-height: 1.2; height:auto;
z-index: 999;
}
`));
document.head.appendChild(style);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment