[HTML5] Build Flexible HTML with HTMLTemplates using Slots and Web Components
HTMLTemplates are part of the web components specification. In this lesson we will learn what are HTML templates, how to use them and how to use the powerful HTMLTemplates slots inside a web component.
<script>
const templateString = `
<div>Some text</div>
<form>
<input name="test"/>
</form>
<slot name="slot1"></slot>
`;
const template = document.createElement('template');
template.innerHTML = templateString;
class MyWebComponent extends HTMLElement {
constructor() {
super();
} connectedCallback() {
this.appendChild(template.content.cloneNode(true));
}
}
window.customElements.define('custom-element', MyWebComponent);
</script>
<custom-element>
<p slot="slot1">This is a slotted paragraph</p>
</custom-element>
<custom-element>
<iframe slot="slot1" width="560" height="315" src="https://www.youtube.com/embed/Bv_5Zv5c-Ts" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</custom-element>
[HTML5] Build Flexible HTML with HTMLTemplates using Slots and Web Components的更多相关文章
- (转)HTML5开发学习(3):本地存储之Web Sql Database
原文:http://www.cnblogs.com/xumingxiang/archive/2012/03/25/2416386.html HTML5开发学习(3):本地存储之Web Sql Data ...
- HTML5和CSS3不仅仅是两项新的Web技术标准
HTML5和CSS3不仅仅是两项新的Web技术标准 HTML5和CSS3不仅仅是两项新的Web技术标准,更代表了下一代HTML和CSS技术.虽然HTML5的标准规范还没有正式发布,但是未来的发展前景已 ...
- 基于 HTML5 WebGL 的计量站三维可视化监控系统 Web 组态工控应用
得益于 HTML5 WebGL 技术的成熟,从技术上对工控管理的可视化,数据可视化变得简单易行!完成对工控设备的管理效率,资源管理,风险管理等的大幅度提高,同时也对国家工业4.0计划作出有力响应! 如 ...
- lightning & web components & templates & slots
lightning & web components & templates & slots Web components, Custom elements, Template ...
- Web Components & HTML5 & template & slot
Web Components & HTML5 & template & slot https://developer.mozilla.org/en-US/docs/Web/HT ...
- 为HTML5开发人员量身打造的7个Web框架
HTML5规范开发完成时,将成为主流.据统计2013年全球将有10亿手机浏览器支持HTML5,同时HTML Web开发者数量将达到200万.毫无疑问,HTML5将成为未来5-10年内,移动互联网领域的 ...
- 使用 HTML5, javascript, webrtc, websockets, Jetty 和 OpenCV 实现基于 Web 的人脸识别
这是一篇国外的文章,介绍如何通过 WebRTC.OpenCV 和 WebSocket 技术实现在 Web 浏览器上的人脸识别,架构在 Jetty 之上. 实现的效果包括: 还能识别眼睛 人脸识别的核心 ...
- 【JavaScript Weekly】#471 — JANUARY 17, 2020
https://javascriptweekly.com/issues/471 #471 — JANUARY 17, 2020 READ ON THE WEB JavaScript Weekly Ba ...
- [转]使用Flexible实现手淘H5页面的终端适配
曾几何时为了兼容IE低版本浏览器而头痛,以为到Mobile时代可以跟这些麻烦说拜拜.可没想到到了移动时代,为了处理各终端的适配而乱了手脚.对于混迹各社区的偶,时常发现大家拿手机淘宝的H5页面做讨论—— ...
随机推荐
- [水煮 ASP.NET Web API2 方法论](12-3)OData 查询
问题 Web API 怎么支持通用的 OData 系统查询项,例如 $select 或 $filter. 解决方案 为了在 Web API 中启用查询项,我们需要在 Action 上使用 Enable ...
- 通过url判断当前页,动态给导航加样式
//通过url判断当前页,动态给导航加样式 var str =location.pathname; var index = str.lastIndexOf("\/"); str = ...
- 谈谈对final的理解
1.final修饰类 类不能被继承,类中的所有方法都是final的 2.final修饰方法 方法不能被覆盖,private修饰的方法隐性的添加了final 3.final修饰方法内参数 方法内的参数不 ...
- 配置nginx作为下载站点
nginx默认情况是不允许列出整个目录浏览下载 1)autoindex参数详解 autoindex on //on开启目录浏览 autoindex_exact_size off; //off显示出文件 ...
- Python urllib2 设置超时时间并处理超时异常
可以使用 except: 捕获任何异常,包括 SystemExit 和 KeyboardInterupt,不过这样不便于程序的调试和使用 最简单的情况是捕获 urllib2.URLError try: ...
- [thinkphp] 无限极分类
<?php /* * 无限极分类 类 */ header("Content-Type: text/html; charset=UTF-8"); Class Category ...
- Comet OJ CCPC-Wannafly Winter Camp Day1 (Div2, online mirror) F.爬爬爬山-最短路(Dijkstra)(两个板子)+思维(mdzz...) zhixincode
爬爬爬山 已经提交 已经通过 9.83% Total Submission:417 Total Accepted:41 题目描述 爬山是wlswls最喜欢的活动之一. 在一个神奇的世界里,一共有nn座 ...
- python笔记一:函数的参数
1.默认参数 def fun(x,y,z=3): sum=x+y+z return sum fun(1,2) 2.可变参数(两种方法定义) def fun(n): sum=0 for i in n: ...
- Flask实战第54天:cms删除轮播图功能完成
后台逻辑 编辑cms.views.py @bp.route('/dbanner/',methods=['POST']) @login_required def dbanner(): banner_id ...
- [NOI 2011][BZOJ 2434] 阿狸的打字机
传送门 AC自动机 + 树状数组 建成AC自动机后,设end[i]为第i个串的末尾在Trie树上的节点. 可以发现,对于一个询问(x,y),ans等于Trie树上root到end[y]这条链上fail ...