Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the interfaces of 5 unknown HTML5?

Shulou Source: shulou.com Published: 2022-06-03 07:46:30 09月12日 Update

5 do not know what the interface of HTML5 is, I believe that many inexperienced people do not know what to do about this, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

When people see or say the word "HTML5", it is estimated that at least half of them will think that she is not only a sexy and charming beauty, but also a unicorn who can mess you up. Can you blame us developers?

We noticed that the basic Api stagnation has developed for such a long time (about 1999-2009) that it takes us a long time to deal with a basic additional function like "placeholder".

Although current mainstream browsers have implemented a lot of new HTML5 features, many developers simply don't notice these more concise and useful API.

Element.classList

This property has been released for several years, and with classList, we can manipulate the class property of the underlying css through JavaScript.

The code is as follows:

The code is as follows:

/ / use the classList attribute (Dom element, css class name)

Function toggleClassList (element,cName) {

/ / 1. ClassList API

/ / switch classes, remove if there is, add if not

If (element.classList.toggle) {

Element.classList.toggle (cName)

Return true

}

/ /! In fact, if this function toggleClassList is supported

/ / then the following code will not be executed. Here is only a demonstration. Please apply it flexibly.

/ / 2. ClassList API

/ / whether the class attribute of element contains the CSS class hide

Var hasHide = element.classList.contains (cName)

/ /

If (hasHide) {

/ / 3. ClassList API

/ / remove the hide class

Element.classList.remove (cName)

} else {

/ / 4. ClassList API

/ / add hide class

Element.classList.add (cName)

}

Return true

}

ContextMenu API

After testing, chrome28 doesn't work.

The new API,ContextMenu is an excellent interface: this interface allows you to easily add menu items to the browser's context menu (right-click menu), rather than overriding the browser's default right-click menu.

It is important to note that it is best to use the js script to create menu contextmenu dynamically, so as to avoid redundant HTML code if the JS script is disabled on the page.

The code is as follows:

The code is as follows:

Click this area to view the menu

Tags: Code elements attributes menus support interfaces more browsers functions characters developers time whitespace class names pages switching processing development presentation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple Xiaomi NVidia macOS