


Introduction to SVG 2D in HTML5 8—Summary of document structure and related elements_html5 tutorial skills
Many basic elements have been introduced before, including structure-related combinations and reuse elements. Here we will briefly summarize the remaining relevant elements in the document structure of SVG, and then move forward to appreciate other features of SVG.
The elements of SVG documents can basically be divided into the following categories:
•Animation elements: animate, animateColor, animateMotion, animateTransform, set;
•Explanation elements: desc, metadata, title;
•Graphics Elements: circle, ellipse, line, path, polygon, polyline, rect;
• Structural elements: defs, g, svg, symbol, use;
• Gradient elements: linearGradient, radialGradient;
• Other elements :a,altGlyphDef,clipPath,color-profile,cursor,filter,font,font-face,foreignObject,image,marker,mask,pattern,script,style,switch,text,view, etc.
Among them, graphic elements, gradient elements, text, image elements and combinations have all been introduced. Here are several other elements related to structure.
View-svg element
You can place any other elements in any order within the svg element, including nested svg elements.
The commonly used attributes supported by the svg element are id, class, x, y, width, height, viewBox, preserveAspectRatio, and related attributes of fill and stroke.
The events supported by the svg element are also commonly used onload, onmouseover, onmousemove, onmousedown, onmouseup, onclick, onfocusin, onfocusout, onresize, onscroll, onunload, etc. Not much to say about the svg element. For a complete list of attributes and events, please refer to the official documentation later.
Explanatory elements-desc element and title element
Each container element (an element that can contain other container elements or graphic elements, such as: a, defs, glyph, g, Marker, mask, missing-glyph, pattern, svg, switch and symbol) and graphic elements can contain desc and title elements, both of which are auxiliary elements used to explain related situations; their contents are text . When the SVG document is rendered, these two elements will not be rendered into the graphic. The difference between these two elements is not too big. In some implementations, title appears as prompt information, so title is usually placed in the first position of the parent element.
Typical usage is as follows:
< ;svgxmlns="http://www.w3.org/2000/svg" version="1.1"width="4in"height="3in">
Thisisabarchartwhichshows
companysalesbyregion.
🎜>
Usually, the outermost svg element should be accompanied by a title description, so that the program is more readable.
Marker-marker element
Marker defines graphic elements (arrows and multi-point markers) attached to one or more vertices (path, line, polyline or polygon vertices) ). Arrows can be made by attaching a marker to the start or end point of a path, line, or polyline. Multipoint markers can attach a marker to all vertices of a path, line, polyline or polygon. The
mark is defined by the marker element, and then just set the relevant attributes (marker, marker-start, marker-mid, and marker-end) in path, line, polyline or polygon. Take an example:
xmlns="http://www.w3.org/2000/svg">
markerUnits="strokeWidth"
markerWidth="4"markerHeight="3"
orient="auto">
marker-end="url(#Triangle)"/> ;
Let’s take a detailed look at marker-related knowledge:
1. Marker is a container element that can store graphic elements, container elements, animations, gradient elements, etc. in any order.
2. The marker element can create a new view window: set the value of the viewBox.
3. Marker’s more important attributes:
markerUnits="strokeWidth|userSpaceOnUse"
This attribute defines the coordinate system used by the attributes markerWidth, markerHeight and marker content. This attribute has two optional values. The first value, strokeWidth, is the default value, which means that the units of the coordinate system used by the attributes markerWidth, markerHeight and the content of the marker are equal to the value set by the stroke-width of the graphic element that references the marker.
For example, in the above example, the width of the marker element is 400 and the height is 300. However, do not be confused. The coordinates used by the path in the mark element are the new user coordinate system set by the viewBox.
Another value of this attribute is userSpaceOnUse, which means that the attributes markerWidth, markerHeight and the content of the marker use the coordinate system of the graphic element that references the marker.
refX, refY: Define the position coordinates of the referenced point aligned with the marker. For example, in the above example, the referenced point is the end point, and it should be aligned to the (0,5) position of the marker. Note that refX and refY use the end-user coordinate system transformed by the viewBox.
markerWidth, markerHeight: The width and height of the marker window. This is easy to understand.
orient: defines the angle of marker rotation. You can specify an angle or assign auto directly.
auto means that the positive direction of the x-axis is rotated according to the following rules :
a. If the point where the marker is located only belongs to one path, the positive x-axis direction of the marker is the same as the direction of the path. See the example above.
b. If the point where the marker is located belongs to two different paths, then the positive x-axis direction of the marker is consistent with the angular bisector of the angle between the two paths.
4. Marker attributes of graphic elements
If a graphic element wants to reference a marker, it needs to use related attributes, mainly these three: marker-start (put the referenced marker at the starting point), marker- mid (place the referenced marker at all points except the starting point and end point), marker-end (place the referenced marker at the end point). The values of these three attributes may be none (meaning not to reference the marker), marker reference (referencing a certain marker), and inherit (no need to say more about this).
You can also see the usage of markers from the above example.
Script and style-script element and style element
In fact, basically all attributes (for all elements, not just text) can be associated with an element using CSS, And all CSS properties are available in SVG images. You can directly use the style attribute to style the element, or refer to the style sheet to style the element. Stylesheets should not be parsed for XML files (because they occasionally contain characters that can cause problems), so they need to be placed in an XMLCDATA section. The same goes for scripts, which need to be placed in the XMLCDATA section. Look at the following CSS example:
.abbreviation{text-decoration:underline;}
]]>
< /defs>
Look at the script example again:
functionhideReveal(evt){
varimageTarget=evt.target;
vartheFill=imageTarget.getAttribute("fill");
if(theFill=='white')
imageTarget.setAttribute("fill","url(#notes)");
else
imageTarget.setAttribute("fill","white");
}
]]>
patternUnits="userSpaceOnUse">
条件处理-switch元素
条件处理属性是能控制所在元素渲染与否的属性。基本上大多数的元素(特别是图形元素)都可以指定条件处理属性。条件处理属性有3个:requiredFeatures,requiredExtensions和systemLanguage。这些属性就是一组测试,都允许指定一个值列表(前面两个属性是空格隔开的,语言这个属性是使用逗号隔开的),默认值都为true。
SVG的switch元素提供了按指定条件渲染的能力。switch元素是一个容器元素,可以包含图形元素,解释性元素,动画元素,a,foreignObject,g,image,svg,switch,text,use等元素。switch元素会按顺序检查直接子元素的条件处理属性,然后渲染满足自身条件的的第一个子元素,其他的子元素都会被忽略。这些属性与display属性一样,只会影响直接使用这些属性的元素的渲染,不会影响引用的元素(比如use引用的元素)。简单的说,这3个属性会影响a,altGlyph,foreignObject,textPath,tref,tspan,animate,animateColor,animateMotion,animateTransform,set等元素,不会影响defs,cursor,mask,clipPath,pattern等元素(这些元素那么不是可渲染的,要么就是引用别的元素)。
注意:子元素的display和visibility属性值并不影响switch元素条件判断的结果。
条件处理属性的取值列表参看官方文档,这里就看一个小例子:
fill="black"stroke="none"filter="url(#gblurshadow)"/>
这个例子的意思简单的说就是:使用的浏览器支持filter特性,那么就绘制上面的矩形(带filter属性),如果不支持filter特性,就绘制下面的矩形。
其实更多的时候,用的比较多的属性是systemLanguage,就是文本的多语言处理能力。例如:
实用参考:
脚本索引:http://msdn.microsoft.com/zh-cn/library/ff971910(v=vs.85).aspx
开发中心:https://developer.mozilla.org/en/SVG
热门参考:http://www.chinasvg.com/
官方文档:http://www.w3.org/TR/SVG11/

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use SVG to achieve image mosaic effect without using Javascript? The following article will give you a detailed understanding, I hope it will be helpful to you!

svg can be converted to jpg format by using image processing software, using online conversion tools, and using the Python image processing library. Detailed introduction: 1. Image processing software includes Adobe Illustrator, Inkscape and GIMP; 2. Online conversion tools include CloudConvert, Zamzar, Online Convert, etc.; 3. Python image processing library, etc.

svg images are widely used in projects. The following article will introduce how to use svg icons in vue3 + vite. I hope it will be helpful to everyone!

It only takes two minutes to convert pictures into 3D! It is also the kind with high texture quality and high consistency in multiple viewing angles. No matter what species it is, the single-view image when input is still like this: Two minutes later, the 3D version is completed: △ Upper, Repaint123 (NeRF); Lower, Repaint123 (GS) The new method is called Repaint123. The core idea is to combine 2D The powerful image generation capabilities of the diffusion model are combined with the texture alignment capabilities of the redraw strategy to generate high-quality, consistent images across multiple views. In addition, this study also introduces a visibility-aware adaptive repaint intensity method for overlapping regions. Repaint123 solves the problems of previous methods such as large multi-view deviation, texture degradation, and slow generation in one fell swoop. Current item

With the continuous development of modern Web front-end development, more and more technologies are widely used in actual development. Among them, Vue.js is currently one of the most popular JavaScript frameworks. It is based on the MVVM model and provides a rich API and component library, making it easier to develop responsive, reusable, and efficient web applications. The latest version of Vue.js3 has better performance and richer features than the old version, which has attracted widespread attention and research. This article will introduce to you a

How to add logo to favicon using SVG? The following article will introduce to you how to use SVG to generate favicon with logo. I hope it will be helpful to you!

1. Install vite-plugin-svg-icons. You also need to install fast-glob related dependencies. Otherwise, when vite runs npmrundev, it will report the Cannotfindmodule'fast-glob' error npmifast-glob@3.x-Dnpmivite-plugin-svg. -icons@2.x-D 2. Create a new component index.vueimport{computed}from'vue';cons under src/components/svgIcon

1. Install svg-sprite-loadernpminstallsvg-sprite-loader--save-dev 2. Create a new component under src/components/svgIcon index.vueimport{computed}from"@vue/reactivity";exportdefault{name:"baseSvgIcon", props:{iconClass:{type:String},className:{type:String},},setup
