HTML5 Template in Action

https://developer.mozilla.org/es/docs/Web/HTML/Elemento/template

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5

https://developer.mozilla.org/en-US/docs/Web/CSS/@import

https://www.html5rocks.com/en/tutorials/webcomponents/template/

https://www.html5rocks.com/zh/tutorials/webcomponents/template/


"use strict"; /**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @description HTML5 Template
* @augments
* @example
*
*/ /* <template>
<h2>Flower</h2>
<img src="https://www.w3schools.com/tags/img_white_flower.jpg">
</template> <template>
<div class="myClass">I like: </div>
</template> */ const showContent = () => {
// let temp = document.getElementsByTagName("template")[0],
let temp = document.querySelector(`[data-tempalte="tempalte-img"]`),
clone = temp.content.cloneNode(true);
document.body.appendChild(clone);
}; const templateGenerator = (datas = [], debug = false) => {
let result = ``;
// let temp = document.getElementsByTagName("template")[1],
let temp = document.querySelector(`[data-tempalte="tempalte-links"]`),
item = temp.content.querySelector("div");
for (let i = 0; i < datas.length; i++) {
let a = document.importNode(item, true);
a.textContent += datas[i];
document.body.appendChild(a);
}
return result;
}; const arr = ["Audi", "BMW", "Ford", "Honda", "Jaguar", "Nissan"]; if (document.createElement("template").content) {
console.log("YES! The browser supports the template element");
templateGenerator(arr);
setTimeout(() => {
showContent();
}, 0);
} else {
console.error("No! The browser does not support the template element");
}

blogs

https://www.w3schools.com/html/html5_intro.asp

https://www.w3schools.com/tags/tag_template.asp

  1. The <template> tag holds its content hidden from the client.

  2. Content inside a <template> tag will not be rendered.

  3. The content can be visible and rendered later by using JavaScript.

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_template2


<button onclick="showContent()">Show template</button> <template>
  <h2>Flower</h2>
  <img src="https://www.w3schools.com/tags/img_white_flower.jpg" width="214" height="204">
</template>

const showContent = () => {
let temp = document.getElementsByTagName("template")[0],
clone = temp.content.cloneNode(true);
document.body.appendChild(clone);
};

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_template3


SSE: Server-Sent Event

https://www.w3schools.com/html/html5_serversentevents.asp

EventSource

Check Server-Sent Events Support

Create a new EventSource object, and specify the URL of the page sending the updates


if(typeof(EventSource) !== "undefined") {
// Yes! Server-sent events support!
var source = new EventSource("demo_sse.php");
source.onmessage = function(event) {
document.getElementById("result").innerHTML += event.data + "<br>";
};
} else {
// Sorry! No server-sent events support..
}

text/event-stream

Server-Side Code Example

For the example above to work, you need a server capable of sending data updates (like PHP or ASP).

The server-side event stream syntax is simple. Set the "Content-Type" header to "text/event-stream". Now you can start sending event streams.


<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache'); $time = date('r');
echo "data: The server time is: {$time}\n\n";
flush(); ?>

https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_sse



"use strict"; /**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @description HTML5 Template
* @augments
* @example
*
*/ /* <template>
<h2>Flower</h2>
<img src="https://www.w3schools.com/tags/img_white_flower.jpg">
</template> <template>
<div class="myClass">I like: </div>
</template> */ const showContent = () => {
// let temp = document.querySelector(`[data-tempalte="tempalte-img"]`);
let temp = document.getElementsByTagName("template")[0],
clone = temp.content.cloneNode(true);
document.body.appendChild(clone);
}; const templateGenerator = (datas = [], debug = false) => {
let result = ``;
// do something...
//get the template element:
let temp = document.getElementsByTagName("template")[1];
// let temp = document.querySelector(`[data-tempalte="tempalte-links"]`);
//get the DIV element from the template:
let item = temp.content.querySelector("div");
//for each item in the array:
for (let i = 0; i < datas.length; i++) {
//Create a new node, based on the template:
let a = document.importNode(item, true);
//Add data from the array:
a.textContent += datas[i];
//append the new node wherever you like:
document.body.appendChild(a);
}
return result;
}; const arr = ["Audi", "BMW", "Ford", "Honda", "Jaguar", "Nissan"]; if (document.createElement("template").content) {
console.log("YES! The browser supports the template element");
templateGenerator(arr);
setTimeout(() => {
showContent();
}, 0);
} else {
console.error("No! The browser does not support the template element");
}

responsive-html5-web-templates

https://www.mockplus.com/blog/post/free-responsive-html5-web-design-templates

https://colorlib.com/wp/free-business-website-templates/

HTML5 Template in Action的更多相关文章

  1. [MODx] 1. Add Html5 template into the MODx

    1. Connet MODx by SSH: Go to the MODx cloud; Find you current user and right click selet Edit Cloud; ...

  2. HTML5 template元素

    前言 转自http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/ 在单页面应用,我们对页面的无刷新有了更高的要求,H ...

  3. HTML5 <template>标签元素简介

    一.HTML5 template元素初面 <template>元素,基本上可以确定是2013年才出现的.干嘛用的呢,顾名思意,就是用来声明是“模板元素”. 目前,我们在HTML中嵌入模板H ...

  4. [转]HTML5 Day 4: Add Drop Down Menu to ASP.NET MVC HTML5 Template using CSS and jQuery

    本文转自:http://pietschsoft.com/post/2010/11/17/HTML5-Day-4-Add-DropDown-Menu-ASPNET-MVC-HTML5-Template- ...

  5. HTML5 Canvas in Action

    HTML5 Canvas in Action canvas 图片处理 视频编辑工具 xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

  6. Web Components & HTML5 & template & slot

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

  7. HTML5 <template>

    http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/

  8. HTML语义化:HTML5新标签——template

    一.前言 当我们使用String-base的模板引擎(如Handlebars.js等)时,要么就通过外部文件存放模板文本,需要时再通过XHR或script标签加载进来:要么通过<script t ...

  9. HTML5中<template>标签的详细介绍

    HTML5中<template>标签的详细介绍(图文) 这篇文章主要介绍了HTML5中的template标签,是HTML5入门中的重要知识,需要的朋友可以参考 一.HTML5 templa ...

随机推荐

  1. jackson学习之四:WRAP_ROOT_VALUE(root对象)

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  2. SpringBoot深入理解

    SpringBoot深入理解 项目打包SpringBoot启动过程 当使用打包时,会下载org-springframework-boot-loader的jar,并且不会放在lib存放的第三方jar包文 ...

  3. day03 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数

    本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数 温故知新 1. 集合 主要作用: 去重 关系测 ...

  4. 系列trick - 随机

    系列trick - 随机 不断更新中,欢迎来提供idea 随机的字符串 出现次数 \(\ge 2\) 的子串期望长度是 \(\log n\) 两个随机串的期望LCP,LCSuf,LCSub长度是 \( ...

  5. BZOJ2120 数颜色(带修改的莫队算法)

    Description 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜 ...

  6. Fiddler扩展——自定义列数据&Tunnel to 443解决办法

    在平时日常工作中,使用Fiddler的占比还是蛮大的.使用过程,也会遇到一些小问题,问题虽小,但抓不到包,分析不了问题与数据,那也是件麻烦的事情. 以前也分享过一些小技巧,可以找以前的博文查看,具体地 ...

  7. SSM、SSH框架搭建,面试点总结

    文章目录 1.SSM如何搭建:三个框架的搭建: 2.SSM系统架构 3.SSM整合步骤 4.Spring,Spring MVC,MyBatis,Hibernate个人总结 5.面试资源 关于SSM.S ...

  8. java架构《并发线程高级篇一》

    本章主要记录讲解并发线程的线程池.java.util.concurrent工具包里面的工具类. 一:Executor框架: Executors创建线程池的方法: newFixedThreadPool( ...

  9. EXCEL序列

  10. 微信小程序分享之生成海报--canvas

    首先看文档 了解知识点~~(https://developers.weixin.qq.com/miniprogram/dev/component/) githup:https://github.com ...