


How to use SVG to generate a cool page preloading sketch animation effect_html/css_WEB-ITnose
Online Demo
Local Download
1 Introduction to SVG
Scalable Vector Graphics It is a graphics format based on Extensible Markup Language (a subset of Standard Universal Markup Language) for describing two-dimensional vector graphics. It is developed by the World Wide Web Consortium and is an open standard.
2 Features of SVG
Compared with other image formats (such as JPEG and GIF), the advantages of using SVG are:
SVG images can be created through a text editor and modify
SVG images can be searched, indexed, scripted or compressed
SVG is scalable
SVG images can be produced at any resolution with high quality Print
SVG can be enlarged without loss of image quality
3 browser support
Internet Explorer 9, Firefox, Opera, Chrome And Safari supports inline SVG. Internet Explorer 8 or earlier can support SVG by installing Adobe SVG Viewer.
4 SVG tags
SVG code starts with the
5 SVG example of making sketch line animation
1) First draw a sketch line as shown in the picture:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 200 100"> <!-- fill属性是否填充 stroke为绘制,颜色#AAAAAA stroke-width为绘制线的粗细 d是具体数据,这里看到的数据代表了坐标,以及折线等等,可以使用工具生成 --> <path fill="none" stroke="#AAA" stroke-width="2" d="M62.9 14.9c-25-7.74-56.6 4.8-60.4 24.3-3.73 19.6 21.6 35 39.6 37.6 42.8 6.2 72.9-53.4 116-58.9 65-18.2 191 101 215"></path> </svg>
The parameters of the sketch line can be generated using tools,
Introduction to basic SVG tags in related courses
2) Animation and principles of SVG sketch
stroke-dasharray = "100 10" stroke-dashoffset = "0"
stroke-dasharray defines the length of the generated line segment and the gap between the line segment and the line segment. It contains two parameters
stroke-dashoffset defines the distance from that line segment. The position starts rendering to generate a line segment
Related courses Sketch animation simulation effect and its principle realized by SVG
3) Use CSS3 to realize sketch animation effect
/*定义keyframe动画*/ /* 添加动画到path元素 */ .path{ stroke-dasharray: 265.07; stroke-dashoffset: 265.07; animation: dash 3s linear infinite; /* 支持chrome */ -webkit-animation: dash 3s linear infinite; } @keyframes dash{ from{ stroke-dashoffset: 265.07; /* 这里是svg图形中素描线长度,可以使用js获取 */ } to{ stroke-dashoffset: 0; } } /* 支持chrome浏览器 */ @-webkit-keyframes dash{ from{ stroke-dashoffset: 265.07; /* 这里是svg图形中素描线长度,可以使用js获取 */ } to{ stroke-dashoffset: 0; } }
Related courses use CSS3 to achieve sketch animation effects
4) Use Javascript to adjust the parameters of animation effects
/*定义相关Javascript*/ var current_frame, //定义当前帧 total_frames, //定义全部帧数 path, //定义svg中的唯一path元素 length, //定义path所生成的素描长度 handle; //定义javascript动画句柄 path = document.getElementById('path'), length = path.getTotalLength(); //定义初始化方法 var init = function(){ current_frame = 0; total_frames = 160; path.style.strokeDasharray = length + ' ' + length; //定义dasharray path.style.strokeDashoffset = length; //定义dashoffset handle = 0; } //定义实际的动画绘制方法 var draw = function(){ var progress = current_frame/total_frames; if(progress>1){ //这里定义完成动画 window.cancelAnimationFrame(handle); }else{//否则使用reqeuestAnimationFrame来生成动画 current_frame++; path.style.strokeDashoffset = Math.floor(length*(1 - progress)); handle = window.requestAnimationFrame(draw); } } //定义一个重新运行方法 var rerun = function(){ init(); draw(); } //页面加载即运行 rerun();
Here are the main Define the initialization method and animation drawing method, window.requestAnimationFrame(draw);
to generate animation.
Related courses Use Javascript to achieve sketch animation effects
5) We choose the logo of the Geek tag as the original image, and the coordinate parameters are generated with the Inkscape tool.
When running the animation drawing program, each line is drawn in the set way, and we will see a very cool preloaded animation.
To see the full effect, please visit the light video course: Use javascript to generate the sketch animation effect of the geek tag logo

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.