Home > Web Front-end > H5 Tutorial > body text

HTML5 - A closer look at embedded content

黄舟
Release: 2017-03-11 16:44:19
Original
1679 people have browsed it

1. Embed images

The img element allows us to embed images in HTML documents. The image is not loaded until the HTML markup has been processed! ! The

  • src attribute specifies the URL of the image to be embedded; the

  • alt attribute defines the alternative content of the img element (rendered when the image cannot be displayed).

  • The width and height attributes specify the size (in pixels) of the image represented by the img element. If this attribute is omitted, the browser does not know how much screen space to allow for the image. The result is that the browser must rely on the image file itself to determine its size and then relocate the on-screen content to accommodate it, resulting in Shake.

1. Embed images in hyperlinks

Example: Use img and a elements to create a server-side partitioned response graph

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>使用img和a元素创建服务器端的分区响应图</title></head><body><a href="otherpage.html">
    <img src="../images/sport.jpg" ismap alt="奥运会运动项目" width="520px" height="131px"></a></body></html>
Copy after login
http://localhost:63342/html_test/public/embeddedContent_Chapter15/otherpage.html?466,39
Copy after login

Adding the ismap attribute creates a server-side partition response graph, and the URL address will contain the coordinates of the mouse click.

2. Create a client-side partition response graph

Create a client-side partition response graph and let the browser navigate to different URLs by clicking on different areas on an image.

  • The map element contains one or more area elements, each of which represents a clickable area on the image.

  • The attributes of the area element can be divided into two categories: the first category deals with the URL that the browser will navigate to after the image area represented by the area is clicked by the user; the second category Contains shape and coords attributes to indicate various image areas that the user can click.

Table area element attributes related to the target address

AttributeDescription
hrefThe URL that the browser should load when this area is clicked
altAlternate content
targetThe browsing context that should be used to display the URL
rel Describes the relationship between the current document and the target document
meidaMedia applicable to this area
hreflangThe language of the target document
typeThe MIME type of the target document

The values ​​of table shape and coords attributes

Attributescoords value properties and meaning
rect represents a rectangular area. The coords attribute must consist of four comma-separated integers (left, top, right, bottom)
circle represents a circular area. The coords attribute must consist of three integers separated by commas (the distance from the left edge to the center of the circle, the distance from the upper edge to the center of the circle, and the radius)
poly represents a polygon. The coords attribute must contain at least six integers separated by commas (each number represents a vertex of the polygon)
defaultThe default area, which covers the entire sheet Picture

Example: Creating a Partitioned Response Graph
HTML5 - A closer look at embedded content

<p>
    <img src="../images/sport.jpg" usemap="#sportmap" alt="Sport image"></p><map name="sportmap">
    <area href="archery.html" shape="rect" coords="0,5,90,125" alt="射箭">
    <area href="swimming.html" shape="rect" coords="120,5,250,125" alt="游泳">
    <area href="weightlifting.html" shape="rect" coords="290,5,390,125" alt="举重">
    <area href="hockey.html" shape="rect" coords="420,5,520,125" alt="曲棍球">
    <area href="sport.html" shape="default" alt="运动"></map>
Copy after login

Note:
1. Add the usemap attribute to the img element; associate it with the map element.
2. There is no need to use the a element to display hyperlinks.

2. Embedding an HTML document

The iframe element allows us to embed another document in an existing HTML document.

Example: Using iframe elements
HTML5 - A closer look at embedded content

<header>
    <nav>
        <ul>
            <li>
                <a href="img_a.html" target="myframe">Img a Demo</a>
            </li>
            <li>
                <a href="img_map.html" target="myframe">Img map Demo</a>
            </li>
        </ul>
    </nav></header><iframe name="myframe" width="300" height="100"></iframe>
Copy after login

In the above example, an iframe element with the name attribute myframe is created, thus creating an iframe element with the name is the browsing context of myframe. This browsing context is then used in conjunction with the target attribute of other elements (specifically a, form, button, input, and base). In the example, the URL specified in the href attribute will be loaded into the iframe.

Other attributes of the table

AttributesDescription
srcSpecify the URL that the iframe should load and display at the beginning
srcdocDefine a URL for inlining Displayed HTML document
seamlessDisplay iframe content as if it were an integral part of the main HTML document (not supported by the browser)
sandboxRestrict HTML documents (not supported by the browser)

三、 通过插件嵌入内容

object和embed元素最初都是作为扩展浏览器能力的一种方式,用于添加插件支持,而插件能够处理浏览器不直接支持的内容。

示例:嵌入视频

<embed src="https://www.youtube.com/embed/jItLiNKSCBg" 
    width="560" height="349" allowfullscreen="true"><object data="https://www.youtube.com/embed/jItLiNKSCBg"
        width="560" height="349">
    <param name="allowFullScreen" value="true">
    <b>Sorry!</b>We can&#39;t display this content</object>
Copy after login

示例:用object元素嵌入一张图像

<object data="../images/sport.jpg" type="image/jpg"></object>
Copy after login

示例:用object元素创建一张客户端分区响应图

<header>
    <nav>
        <ul>
            <li>
                <a href="img_a.html" target="myframe">Img a Demo</a>
            </li>
            <li>
                <a href="img_map.html" target="myframe">Img map Demo</a>
            </li>
        </ul>
    </nav></header><object type="text/html" name="myframe" width="300" height="100"></object>
Copy after login

注意:chrome和Safari目前不支持用object元素创建客户端分区响应图

示例:用object元素创建浏览器上下文

<p>
    <object type="image/jpg" data="../images/sport.jpg" usemap="#sportmap"></object></p><map name="sportmap">
    <area href="archery.html" shape="rect" coords="0,5,90,125" alt="射箭">
    <area href="swimming.html" shape="rect" coords="120,5,250,125" alt="游泳">
    <area href="weightlifting.html" shape="rect" coords="290,5,390,125" alt="举重">
    <area href="hockey.html" shape="rect" coords="420,5,520,125" alt="曲棍球">
    <area href="sport.html" shape="default" alt="运动"></map>
Copy after login

四、嵌入数字表现形式

1. 显示进度

progress元素可以用来表现某项任务逐渐完成的过程。
value属性定义了当前的进度,它位于0和max属性的值所构成的范围之间。当max属性被省略时,范围是0至1。

示例:使用progress元素

<progress id="myprogress" value="10" max="100"></progress><p>
    <button type="button" value="30">30%</button>
    <button type="button" value="60">60%</button>
    <button type="button" value="90">90%</button></p><script>
    var buttons = document.getElementsByTagName("button");    
    var progress = document.getElementsByTagName("progress")[0];    
    for(var i = 0, len = buttons.length; i < len; i++){
        buttons[i].onclick = function(e){
            progress.value = e.target.value; // 千万不能通过 buttons[i].value 获取值
        }
    }</script>
Copy after login

2. 显示范围里的值

meter元素显示了某个范围内所有可能值中的一个。
min和max属性设定了可能值所处范围的边界,它们可以用浮点数表示。
meter元素的显示可以分为三个部分:过低、过高和最佳。

  • low属性设置一个值,在它之下的所有值都被认为是过低;

  • high属性设置一个值,在它之上的所有值都被认为是过高;

  • optimum属性则指定了“最佳”的值。

<meter id="mymeter" value="90"
       min="0" max="100"
       low="40" high="80" optimum="60"></meter><p>
    <button type="button" value="30">30</button>
    <button type="button" value="60">60</button>
    <button type="button" value="90">90</button></p><script>
    var buttons = document.getElementsByTagName("button");    
    var meter = document.getElementById("mymeter");    
    for(var i = 0, len = buttons.length; i < len; i++){
        buttons[i].onclick = function(e){
            meter.value = e.target.value;
        }
    }</script>
Copy after login

The above is the detailed content of HTML5 - A closer look at embedded content. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!