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的更多相关文章

  1. (转)HTML5开发学习(3):本地存储之Web Sql Database

    原文:http://www.cnblogs.com/xumingxiang/archive/2012/03/25/2416386.html HTML5开发学习(3):本地存储之Web Sql Data ...

  2. HTML5和CSS3不仅仅是两项新的Web技术标准

    HTML5和CSS3不仅仅是两项新的Web技术标准 HTML5和CSS3不仅仅是两项新的Web技术标准,更代表了下一代HTML和CSS技术.虽然HTML5的标准规范还没有正式发布,但是未来的发展前景已 ...

  3. 基于 HTML5 WebGL 的计量站三维可视化监控系统 Web 组态工控应用

    得益于 HTML5 WebGL 技术的成熟,从技术上对工控管理的可视化,数据可视化变得简单易行!完成对工控设备的管理效率,资源管理,风险管理等的大幅度提高,同时也对国家工业4.0计划作出有力响应! 如 ...

  4. lightning & web components & templates & slots

    lightning & web components & templates & slots Web components, Custom elements, Template ...

  5. Web Components & HTML5 & template & slot

    Web Components & HTML5 & template & slot https://developer.mozilla.org/en-US/docs/Web/HT ...

  6. 为HTML5开发人员量身打造的7个Web框架

    HTML5规范开发完成时,将成为主流.据统计2013年全球将有10亿手机浏览器支持HTML5,同时HTML Web开发者数量将达到200万.毫无疑问,HTML5将成为未来5-10年内,移动互联网领域的 ...

  7. 使用 HTML5, javascript, webrtc, websockets, Jetty 和 OpenCV 实现基于 Web 的人脸识别

    这是一篇国外的文章,介绍如何通过 WebRTC.OpenCV 和 WebSocket 技术实现在 Web 浏览器上的人脸识别,架构在 Jetty 之上. 实现的效果包括: 还能识别眼睛 人脸识别的核心 ...

  8. 【JavaScript Weekly】#471 — JANUARY 17, 2020

    https://javascriptweekly.com/issues/471 #471 — JANUARY 17, 2020 READ ON THE WEB JavaScript Weekly Ba ...

  9. [转]使用Flexible实现手淘H5页面的终端适配

    曾几何时为了兼容IE低版本浏览器而头痛,以为到Mobile时代可以跟这些麻烦说拜拜.可没想到到了移动时代,为了处理各终端的适配而乱了手脚.对于混迹各社区的偶,时常发现大家拿手机淘宝的H5页面做讨论—— ...

随机推荐

  1. java入门概念梳理总结

    Java入门学习 简介 public class HelloWorld { public static void main(String []args) { System.out.println(&q ...

  2. 开始学习NodeJs, javascript, 算法

    我的技术路线是C.C++.C#.PHP,什么都做过,很杂,总想着该怎么继续下去. 最近突然发现了NodeJs,觉得很适合我. 学习环境定在了Ubuntu下,编辑软件选择了WebStorm7. 经过几天 ...

  3. sprint定时任务执行两次

    我这里遇到的是tomcat问题,把appBase设置为空 <Host name="localhost" appBase="" unpackWARs=&qu ...

  4. CentOS 7.4 上如何安装 tomcat 9

    本文将详细讲解在 CentOS 7.4 系统上如何安装tomcat 9,tomcat是没有32位和64位之分的. 创建tomcat的安装路径 首先在/usr/local/下建立一个tomcat的文件夹 ...

  5. java线程基本知识

    如何去定义一个线程?(三种方式)    1.Thread:继承这个类,然后重写run方法:将业务逻辑或任务写到run方法中,然后调用start来启动线程:    2.Runnable: 实现这个接口, ...

  6. redis缓存总结----干货

    Redis的概念 Redis是一款内存高速缓存数据库.Redis全称为:Remote Dictionary Server(远程数据服务),Redis是一个key-value存储系统,它支持丰富的数据类 ...

  7. Bzoj2818 Gcd(莫比乌斯反演)

    题面 题意都在题目里面了 题解 你可以把题意看成这个东西 $$ \sum_{i=1}^n\sum_{j=1}^m\mathbf f(gcd(i,j)) $$ 其中$\mathbf f(n)$为$是否是 ...

  8. 【线段树+离散化】POJ2528-Mayor's posters

    [题目大意] 在墙上贴海报,问最后能看到几张海报? [注意点] 1.首先要注意这是段线段树,而非点线段树.读题的时候注意观察图.来看discuss区下面这组数据: 3 5 6 4 5 6 8 上面数据 ...

  9. 【动态规划/递推】BZOJ1806[IOI2007]- Miners

    IOI历史上的著名水题,我这种蒟蒻都能写的东西. [思路] 用1.2.3分别代替三种食物,0表示当前矿井没有食物.f[i][a][b][c][d]当前第i个食物,矿1的食物顺序由上至下为a,b:矿2的 ...

  10. [转]jQuery 双击事件(dblclick)时,不触发单击事件(click)

    例1: 链接:http://www.w3school.com.cn/jquery/event_dblclick.asp HTML 系列教程 浏览器脚本 服务器脚本 ASP.NET 教程 XML 系列教 ...