Skip to content

Instantly share code, notes, and snippets.

@brianswisher
Created December 22, 2015 15:51
Show Gist options
  • Select an option

  • Save brianswisher/1fb5a79c25d15665934b to your computer and use it in GitHub Desktop.

Select an option

Save brianswisher/1fb5a79c25d15665934b to your computer and use it in GitHub Desktop.
Ultimate Vertical Center
((store, render)=>{
store.htm = `
<div class="-cnt">
<div class="-element">${store.content}</div>
</div>
<style>
#${store.id} .-cnt {
background-color: #ededed;
height: 75vw;
}
#${store.id} .-element {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
</style>
`;
return render(store);
})({id:"App", content: "Hello<br/>World"}, (store)=>{
const
cnt = document.getElementById(store.id) ||
(()=>{
var div = document.createElement("div");
div.id = store.id;
document.body.insertBefore(div, document.body.childNodes[0]);
return div;
})();
if (cnt.innerHTML !== store.htm) cnt.innerHTML = store.htm;
return "done.";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment