Skip to content

Instantly share code, notes, and snippets.

@hzhangxyz
Last active March 31, 2017 13:38
Show Gist options
  • Save hzhangxyz/fcf91934681aa1c83885e02657ccb571 to your computer and use it in GitHub Desktop.
Save hzhangxyz/fcf91934681aa1c83885e02657ccb571 to your computer and use it in GitHub Desktop.
HTML5 element
<script>
window.onload = function(){
var Name = document.registerElement("name-div",{
prototype: Object.create(HTMLDivElement.prototype,{
createdCallback: {
value: function(){
this.shadow = this.createShadowRoot();
}
},
attributeChangedCallback: {
value: function(a,b,c){
if(a=="name"){
this.shadow.innerHTML = `<p>我叫 ${c}</p>`;
}
}
}
})
})
"小红 小黑".split(" ").map((n)=>{
var t = new Name();
t.setAttribute("name", n)
document.body.appendChild(t);
})
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment