Created
May 30, 2016 12:16
-
-
Save freshcutdevelopment/c5589a3baccc9ba07b9e1533e7f4f5e9 to your computer and use it in GitHub Desktop.
Creating a custom element with ShadowDOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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