Skip to content

Instantly share code, notes, and snippets.

@freshcutdevelopment
Created May 30, 2016 12:16
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 freshcutdevelopment/c5589a3baccc9ba07b9e1533e7f4f5e9 to your computer and use it in GitHub Desktop.
Save freshcutdevelopment/c5589a3baccc9ba07b9e1533e7f4f5e9 to your computer and use it in GitHub Desktop.
Creating a custom element with ShadowDOM
var UserBioProto = Object.create(HTMLElement.prototype);
UserBioProto.createdCallback = function(){
var root = this.createShadowRoot();
root.innerHTML = '<style>' +
' div { ' +
' box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12); ' +
' width:300px;' +
' padding:10px;' +
'}'+
' img { ' +
' width:30px;' +
' height:30px;' +
' float:left;' +
' text-align:left;' +
' margin-top:10px;' +
' margin-right:10px;' +
'}'+
' p { ' +
' padding-bottom:0px;' +
'}'+
' .name-tag { ' +
' font-weight:bold;' +
' color:#ee6e73;' +
'}'+
'</style>' +
'<div><img src="img/sauron.jpg"></img> <p><span class="name-tag"> Sauron </span> - The Necromancer </p></div>';
};
var userBio = document.registerElement('user-bio',{
prototype:UserBioProto
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment