博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
html 5 api_5个您不知道HTML5 API
阅读量:2515 次
发布时间:2019-05-11

本文共 3832 字,大约阅读时间需要 12 分钟。

html 5 api

When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature addition like made us "take a minute."  Despite many HTML5 features being implemented in modern browsers, many developers are unaware of some of the smaller, useful APIs available to us.  This post exposes those APIs and was written to encourage you to explore the lessor known HTML5 APIs!

当您说或阅读“ HTML5”时,您会一半期望异国情调的舞者和独角兽走进房间,听着“我很性感,我知道”的曲调。 你能怪我们吗? 我们看到基本的API停滞了很长时间,以至于诸如类的基本功能使我们“花了一分钟”。 尽管现代浏览器中实现了许多HTML5功能,但许多开发人员并未意识到我们可以使用的一些更小,更有用的API。 这篇文章揭露了这些API,旨在鼓励您探索众所周知HTML5 API!

()

The provides the basic CSS controls our JavaScript libraries have been giving us for years:

提供了我们JavaScript库多年来为我们提供的基本CSS控件:

// Add a class to an elementmyElement.classList.add("newClass");// Remove a class to an elementmyElement.classList.remove("existingClass");// Check for existencemyElement.classList.contains("oneClass");// Toggle a classmyElement.classList.toggle("anotherClass");

The epitome of a great API addition: simple and intelligent. to learn about a few other classList properties.

大量API的缩影:简单而智能。 以了解其他一些classList属性。

()

The new is excellent:  instead of overriding the browser context menu, the new ContextMenu API allows you to simply add items to the browser's context menu:

新的非常出色:新的不会覆盖浏览器的上下文菜单,而是允许您简单地将项目添加到浏览器的上下文菜单中:

Note that it's best to create your menu markup with JavaScript since JS is required to make item actions work, and you wouldn't want the HTML in the page if JS is turned off.

请注意,最好使用JavaScript创建菜单标记,因为必须使用JS才能使项目操作生效,并且如果JS处于关闭状态,则您不希望页面中HTML。

()

The allows developers to get and set data- attribute values:

允许开发人员获取和设置data-属性值:

/*  Assuming element:	
*/// Get the elementvar element = document.getElementById("myDiv");// Get the idvar id = element.dataset.id;// Retrieves "data-my-custom-key"var customKey = element.dataset.myCustomKey;// Sets the value to something elseelement.dataset.myCustomKey = "Some other value"; // Element becomes: //

Not much more to say; just like classList, simple and effective.

没有更多的话要说。 就像classList一样,简单有效。

()

The , which has even been supported in IE8 for years, allows for message sending between windows and IFRAME elements:

甚至在IE8中也已经支持多年的 ,它允许在Windows和IFRAME元素之间发送消息:

// From window or frame on domain 1, send a message to the iframe which hosts another domainvar iframeWindow = document.getElementById("iframe").contentWindow;iframeWindow.postMessage("Hello from the first window!");// From inside the iframe on different host, receive messagewindow.addEventListener("message", function(event) {	// Make sure we trust the sending domain	if(event.origin == "https://davidwalsh.name") {		// Log out the message		console.log(event.data);		// Send a message back		event.source.postMessage("Hello back!");	}]);

Messages may only be strings, but you could always use JSON.stringify and JSON.parse for more meaningful data!

消息可能只是字符串,但您始终可以使用JSON.stringify和JSON.parse获得更有意义的数据!

()

The autofocus attribute ensures that a given BUTTON, INPUT, or TEXTAREA element is focused on when the page is ready:

autofocus属性可确保在页面准备就绪时将焦点放在给定的BUTTONINPUTTEXTAREA元素上:

Admittedly the is disorienting for the visually impaired, but on simple search pages, it's the perfect addition.

诚然, 会使视力障碍者迷失方向,但是在简单的搜索页面上,它是完美的选择。

Browser support for each API differs, so use feature detection before using each API.  Take a few moments to read the detailed posts on each feature above -- you'll learn a lot and hopefully get a chance to tinker with each API!

浏览器对每个API的支持各不相同,因此请在使用每个API之前使用功能检测。 花点时间阅读上面每个功能的详细文章-您将学到很多东西,并希望有机会尝试修改每个API!

翻译自:

html 5 api

转载地址:http://tgswd.baihongyu.com/

你可能感兴趣的文章
第五天站立会议内容
查看>>
ATMEGA16 IOport相关汇总
查看>>
JAVA基础-多线程
查看>>
面试题5:字符串替换空格
查看>>
[Codevs] 线段树练习5
查看>>
Amazon
查看>>
component-based scene model
查看>>
Echart输出图形
查看>>
hMailServer搭建简单邮件系统
查看>>
从零开始学习jQuery
查看>>
Spring+SpringMVC+MyBatis深入学习及搭建(四)——MyBatis输入映射与输出映射
查看>>
opacity半透明兼容ie8。。。。ie8半透明
查看>>
CDOJ_24 八球胜负
查看>>
Alpha 冲刺 (7/10)
查看>>
一款jQuery打造的具有多功能切换的幻灯片特效
查看>>
SNMP从入门到开发:进阶篇
查看>>
@ServletComponentScan ,@ComponentScan,@Configuration 解析
查看>>
unity3d 射弹基础案例代码分析
查看>>
thinksns 分页数据
查看>>
os模块
查看>>