蘋果系統使用svg 動畫_為什么要使用SVG圖像:如何為SVG設置動畫并使其快速閃電化

蘋果系統使用svg 動畫

我們為什么要使用SVG? (Why Are We Using SVG?)

The web development sector is growing at a rapid pace, and SVG (scalable vector graphics) images are becoming more popular. As vector images, SVGs are composed of mathematical equations that define the positioning and color of lines and curves which make up graphic shapes and text in XML format. SVGs are used for icons, logos, graphic designs, and fonts.

Web開發部門正在快速發展,SVG(可縮放矢量圖形)圖像正變得越來越流行。 SVG作為矢量圖像由數學方程式組成,這些數學方程式定義了以XML格式構成圖形和文字的直線和曲線的位置和顏色。 SVG用于圖標,徽標,圖形設計和字體。

Using SVGs is an easy choice once you consider the advantages they offer. For a client, you get superb quality on any device. For us as developers, there are even more reasons to use SVG.

一旦考慮了SVG的優勢,使用SVG就是一個容易的選擇。 對于客戶而言,您可以在任何設備上獲得一流的質量。 對于作為開發人員的我們來說,還有更多使用SVG的理由。

Let's discuss some of the benefits of SVG now.

現在讓我們討論SVG的一些好處。

1.基于文本的格式 (1. Text-based format)

SVG elements contain text, which greatly improves the accessibility of a website. But the main advantage is that this text is indexed by search engines. And a user can find an SVG file via Google.

SVG元素包含文本,這大大改善了網站的可訪問性。 但是主要優點是該文本由搜索引擎索引。 用戶可以通過Google查找SVG文件。

2.可擴展性 (2. Scalability)

The quality of SVG images does not depend on the resolution. Unlike images of other formats or icon fonts, SVGs look perfectly sharp on any device with any screen size. Scalability also means that if you use the same image throughout the website but in different sizes, you use a single SVG. You do not have to create multiple copies of it as in the case of PNG. Instead, you embed the same image and define the size of it directly in SVG code.

SVG圖像的質量不取決于分辨率。 與其他格式或圖標字體的圖像不同,SVG在任何屏幕尺寸的任何設備上看起來都非常清晰。 可伸縮性還意味著,如果您在整個網站上使用相同的圖像,但尺寸不同,則將使用一個SVG。 您不必像PNG一樣創建多個副本。 相反,您可以嵌入同一圖像,并直接在SVG代碼中定義其大小。

3.高性能 (3. High performance)

If you prioritize performance, you should use SVG. With SVG, there is no need for an HTTP request to load in an image file. The page loads faster as it has no files to download. Faster loading time translates into better webpage performance and higher search engine ranking. In turn, it improves user experience.

如果您優先考慮性能,則應使用SVG。 使用SVG,無需將HTTP請求加載到圖像文件中。 由于沒有文件可下載,因此頁面加載速度更快。 更快的加載時間可以轉化為更好的網頁性能和更高的搜索引擎排名。 反過來,它可以改善用戶體驗。

4.小文件 (4. Small file size)

The size of simple SVG files is defined by the colors, layers, gradients, effects, and masks that it contains. The size of a PNG or any other raster graphics file is defined by the number of pixels that it consists of. The larger a PNG image is, the heavier it gets in size. This is not the case for SVG icons, though. Also, SVGs can be optimized, and I will tell how later in this article.

簡單SVG文件的大小由其包含的顏色,層,漸變,效果和蒙版定義。 PNG或任何其他柵格圖形文件的大小由其組成的像素數定義。 PNG圖像越大,其尺寸越大。 但是,SVG圖標不是這種情況。 另外,可以優化SVG,我將在本文后面介紹如何進行優化。

5.大量的編輯和動畫制作機會 (5. Numerous editing and animating opportunities)

Unlike raster images, vector images can be edited both in special vector drawing programs and directly in a text editor. You can also edit colors or sizes of SVG icons directly via CSS. As for animating SVGs, it can be done with the help of SMIL, Web Animations API, ?WebGL, or CSS animation. Scroll down to learn more about CSS animation of SVG images.

與光柵圖像不同,可以在特殊的矢量繪圖程序中直接在文本編輯器中編輯矢量圖像。 您還可以直接通過CSS編輯SVG圖標的顏色或大小。 對于SVG動畫,可以借助SMIL,Web Animations API,WebGL或CSS動畫來完成。 向下滾動以了解有關SVG圖像CSS動畫的更多信息。

6.與HTML,XHTML和CSS集成 (6. Integration with HTML, XHTML, and CSS)

SVG was designed “to integrate with and extend other prominent open Web platform technologies, such as X/HTML, CSS, and Javascript”, according to W3C. So, unlike different image formats, this format can be easily integrated with other documents and technologies.

W3C稱 ,SVG被設計為“與其他杰出的開放Web平臺技術集成和擴展,例如X / HTML,CSS和Javascript”。 因此,與不同的圖像格式不同,此格式可以輕松地與其他文檔和技術集成。

7. W3C文檔對象模型支持 (7. W3C Document Object Model support)

There is growing community support for SVG. The World Wide Web Consortium (W3C) has always claimed that the Internet cannot do without vector images. This organization basically created the SVG format, and they actively support it nowadays.

社區對SVG的支持越來越多。 萬維網聯盟 (W3C)一直聲稱,互聯網離不開矢量圖像。 該組織基本上創建了SVG格式 ,如今他們積極支持它。

SVG的不便之處是什么? (What Are the Inconveniences of SVG?)

The large number of small parts makes the use of the SVG format irrational. The more parts an image consists of, the heavier it grows in size.

大量的小部件使SVG格式的使用不合理。 圖像組成的部分越多,其尺寸越大。

For example, here are two SVG maps of the United States. The second one is slightly more detailed than the first one. But the higher level of detail cost almost a fivefold increase in file size – 33 KB compared to 147 KB. If this map was not monochromatic, the increase would be much greater.

例如, 是美國的兩個SVG地圖。 第二個比第一個稍微詳細一些。 但是更高級別的細節使文件大小幾乎增加了五倍,從147 KB增長到33 KB。 如果該圖不是單色的,則增加的幅度將更大。

If the picture is linear and contains a few colors – SVG is a solution. However, if the details matter and there are a lot of them, PNG or JPEG may be more suitable.

如果圖片是線性的并且包含幾種顏色– SVG是一種解決方案。 但是,如果細節很重要,并且細節很多,則PNG或JPEG可能更合適。

Also note that SVG cannot be used for photographs. If you use a photograph on your website, SVG is not the best option. You definitely should go with a raster image format.

另請注意,SVG不能用于照片。 如果您在網站上使用照片,則SVG并非最佳選擇。 您絕對應該使用光柵圖像格式。

如何優化SVG圖像 (How to Optimize SVG Images)

When rendering a vector format, we have to write some extra SVG code. The end result should be optimized using different services. Most often, for optimizing SVG, I use a Node.js tool SVGO. It is quite easy to use, and there is no need to upload the images to other websites.

呈現矢量格式時,我們必須編寫一些額外的SVG代碼。 最終結果應使用不同的服務進行優化。 通常,為了優化SVG,我使用Node.js工具SVGO 。 它非常易于使用,不需要將圖像上傳到其他網站。

如何制作SVG動畫 (How to Animate SVG)

SVG graphics on the web can be animated in a number of ways:

網絡上的SVG圖形可以通過多種方式進行動畫處理:

  1. SMIL, which is the native SVG animation specification

    SMIL,這是本地SVG動畫規范
  2. Web Animations API, which is a native JavaScript API allowing you to create more complex sequential animations without loading any external scripts

    Web動畫API,這是一種本地JavaScript API,可讓您創建更復雜的順序動畫而無需加載任何外部腳本
  3. ?WebGL

    WebGL
  4. CSS animation

    CSS動畫

Let’s consider the last one.

讓我們考慮最后一個。

CSS animation is used in order to avoid overloading your service with big libraries for animating icons and loaders.

使用CSS動畫是為了避免使用大型庫來使圖標和加載器動畫化,從而使服務過載。

To see the example of SVG check the animated yolk, the graphic design of which was initially drawn in Sketch.

要查看SVG的示例,請檢查動畫的蛋黃 ,該蛋黃的圖形設計最初是在Sketch中繪制的。

As you can see here, I use Keyframe Animation Syntax for animation. It is implemented by setting the initial position of an element by id (0%), transition (50%) and final position (100%). To achieve smooth animation, initial and final values are equal.

如您所見,我將關鍵幀動畫語法用于動畫。 通過將元素的初始位置設置為id(0%),過渡(50%)和最終位置(100%)來實現。 為了獲得流暢的動畫效果,初始值和最終值必須相等。

Here are some benefits of using the CSS approach to SVG animation:

使用CSS方法處理SVG動畫有以下好處

  1. You do not need an external library.

    您不需要外部庫。
  2. Preprocessors (like Sass or Less) allow you to create variables.

    預處理程序(如Sass或Less)可以創建變量。
  3. You can use onAnimationEnd and some other animation hooks with native JavaScript.

    您可以將onAnimationEnd和其他一些動畫掛鉤與本機JavaScript結合使用。
  4. This approach is easy to use for responsive web design development because you can modify your animation with media queries.

    這種方法易于用于響應式Web設計開發,因為您可以使用媒體查詢來修改動畫。

The downsides of using CSS animation are the following:

使用CSS動畫的缺點如下:

  1. You cannot produce some complex physics effects, which would make the animation more realistic.

    您無法產生一些復雜的物理效果,這會使動畫更加逼真。
  2. A lot of recalculation needs to be done if you adjust timing.

    如果您調整時間,則需要進行很多重新計算。
  3. CSS and SVG graphics on mobile sometimes require strange hacks.

    移動設備上CSS和SVG圖形有時需要奇怪的技巧。

例如 (For Example)

Still, we can make some interesting projects with the help of simple and trivial CSS animation. For example, I have made a simple game-video using HTML, CSS, and a little bit of JavaScript. All the SVGs were drawn in Sketch. The objective of this game is to save the princess. In any situation, just click. You can find the project at my GitHub.

盡管如此,我們仍可以借助簡單而瑣碎CSS動畫制作一些有趣的項目。 例如,我使用HTML,CSS和一些JavaScript制作了一個簡單的游戲視頻。 所有SVG均以Sketch繪制。 這個游戲的目的是拯救公主。 在任何情況下,只需單擊。 您可以在我的GitHub上找到該項目。

總結 (To Wrap Up)

SVGs are a great image format to go with. They are scalable, lightweight, text-based, and efficient. They are easy to edit, animate, and integrate. Importantly, they are supported by almost any browser except Internet Explorer 8 and Android 2.3.

SVG是一種很棒的圖像格式。 它們是可伸縮的,輕量級的,基于文本的,高效的。 它們易于編輯,制作動畫和集成。 重要的是,除Internet Explorer 8和Android 2.3外,幾乎所有瀏覽器都支持它們。

While learning to work with scalable vector graphics images may take you some time, it is an investment that will pay off considering the benefits of SVG.

雖然學習使用可伸縮矢量圖形圖像可能需要一些時間,但考慮到SVG的優勢,這是一筆可觀的回報。

您對軟件項目有想法嗎? (Do you have an idea for a software project?)

My company KeenEthics is a team of experienced web application developers. In case you need a free estimate of a similar project, feel free to get in touch.

我的公司KeenEthics是一個由經驗豐富的Web應用程序開發人員組成的團隊。 如果您需要對類似項目的免費估算,請隨時與我們聯系

You can read more of similar articles on my Keen Blog. Allow me to suggest you read The Value of User Testing or 7 Cases When You Should Not Use Docker.

您可以在我的Keen博客上類似的文章。 請允許我建議您閱讀《用戶測試的價值或不應該使用Docker的7種情況》 。

聚苯乙烯 (P.S.)

Also, I would like to say "thank you" to Maryna Yanul for coauthoring this article as well as the readers for making it to the end!

另外,我想對瑪麗娜·亞努爾 ( Maryna Yanul)與他人合著這篇文章以及讀者們對本文的結尾表示“謝謝”!

The original article posted on KeenEthics blog can be found here: A Fresh Perspective at Why, When, and How to Use SVG.

可以在以下網址找到發布在KeenEthics博客上的原始文章: 關于為什么,何時以及如何使用SVG的新觀點 。

翻譯自: https://www.freecodecamp.org/news/a-fresh-perspective-at-why-when-and-how-to-use-svg/

蘋果系統使用svg 動畫

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390997.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390997.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390997.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

CSV模塊的使用

CSV模塊的使用 1、csv簡介 CSV (Comma Separated Values),即逗號分隔值(也稱字符分隔值,因為分隔符可以不是逗號),是一種常用的文本 格式,用以存儲表格數據,包括數字或者字符。很多程序在處理數…

Java里面遍歷list的方式

問題:Java里面遍歷list的方式 對于Java語言有點陌生,我嘗試熟悉遍歷list(或者其他集合)的所有方法(或者是其他正確的語法)和它們每一個方法的優缺點 給定 List的list對象,我知道有下列方法去循…

python 重啟內核_Python從零開始的內核回歸

python 重啟內核Every beginner in Machine Learning starts by studying what regression means and how the linear regression algorithm works. In fact, the ease of understanding, explainability and the vast effective real-world use cases of linear regression is…

bzoj千題計劃282:bzoj4517: [Sdoi2016]排列計數

http://www.lydsy.com/JudgeOnline/problem.php?id4517 組合數錯排公式 #include<cstdio> #include<iostream>using namespace std;#define N 1000001const int mod1e97;long long fac[N],inv[N],f[N];void read(int &x) {x0; char cgetchar();while(!isdigit…

chrome啟用flash_如何在Google Chrome中啟用Adobe Flash Player

chrome啟用flashRemember Adobe Flash player? Its that nifty software that lets websites embed videos and web games. Whole websites can even be powered by Flash.還記得Adobe Flash Player嗎&#xff1f; 正是這些漂亮的軟件使網站可以嵌入視頻和網絡游戲。 整個網站…

怎么樣把Java的字符串轉化為字節數組?

問題&#xff1a;怎么樣把Java的字符串轉化為字節數組 有沒有任何方法把Java的字符串轉化為字節數組 我嘗試這樣: System.out.println(response.split("\r\n\r\n")[1]); System.out.println("******"); System.out.println(response.split("\r\n\r\…

Forward團隊-爬蟲豆瓣top250項目-模塊開發過程

項目托管平臺地址:https://github.com/xyhcq/top250 開發模塊功能: 寫入文件功能 開發時間:3小時 實現將爬取到的信息寫入到文件中的功能 實現過程&#xff1a; # 打開文件 fopen("top250.txt","w") 在別的隊員寫的代碼基礎上&#xff0c;加入功能代碼 de…

CSS3 outline-offset 屬性 項目中input會遇到

outline在一個聲明中設置所有的輪廓屬性。outline:顏色&#xff08;outline-line&#xff09;樣式&#xff08;outline-style&#xff09;寬度&#xff08;outline-width&#xff09; outline-offset 屬性對輪廓進行偏移&#xff0c;并在邊框邊緣進行繪制。 輪廓在兩方面與邊框…

回歸分析中自變量共線性_具有大特征空間的回歸分析中的變量選擇

回歸分析中自變量共線性介紹 (Introduction) Performing multiple regression analysis from a large set of independent variables can be a challenging task. Identifying the best subset of regressors for a model involves optimizing against things like bias, multi…

winform窗體模板_如何驗證角模板驅動的窗體

winform窗體模板介紹 (Introduction) In this article, we will learn about validations in Angular template-driven forms. We will create a simple user registration form and implement some inbuilt validations on it. Along with the inbuilt validations, we will a…

【loj6191】「美團 CodeM 復賽」配對游戲 概率期望dp

題目描述 n次向一個棧中加入0或1中隨機1個&#xff0c;如果一次加入0時棧頂元素為1&#xff0c;則將這兩個元素彈棧。問最終棧中元素個數的期望是多少。 輸入 一行一個正整數 n 。 輸出 一行一個實數&#xff0c;表示期望剩下的人數&#xff0c;四舍五入保留三位小數。 樣例輸入…

查找滿足斷言的第一個元素

問題&#xff1a;查找滿足斷言的第一個元素 我剛剛開始使用Java 8的lambdas&#xff0c;我嘗試去實現一些我在函數式語言里面經常用的 例如&#xff0c;大部分的函數式語言里有一些查找函數&#xff0c;針對序列或者list進行操作&#xff0c;返回使得斷言為真的第一個元素。我…

Lock和synchronized的選擇

學習資源:http://www.cnblogs.com/dolphin0520/p/3923167.html 一.java.util.concurrent.locks包下常用的類 1.Lock public interface Lock { void lock();//用來獲取鎖。如果鎖已被其他線程獲取&#xff0c;則進行等待。void lockInterruptibly() throws InterruptedException…

python 面試問題_值得閱讀的30個Python面試問題

python 面試問題Interview questions are quite tricky to predict. In most cases, even peoples with great programming ability fail to answer some simple questions. Solving the problem with your code is not enough. Often, the interviewer will expect you to hav…

spring boot中 使用http請求

因為項目需求&#xff0c;需要兩個系統之間進行通信&#xff0c;經過一番調研&#xff0c;決定使用http請求。服務端沒有什么好說的&#xff0c;本來就是使用web 頁面進行訪問的&#xff0c;所以spring boot啟動后&#xff0c;controller層的接口就自動暴露出來了&#xff0c;客…

arduino joy_如何用Joy開發Kubernetes應用

arduino joyLet’s face it: Developing distributed applications is painful.讓我們面對現實&#xff1a;開發分布式應用程序很痛苦。 Microservice architectures might be great for decoupling and scalability but they are intimidatingly complex when it comes to de…

怎么樣得到平臺相關的換行符?

問題&#xff1a;怎么樣得到平臺相關的換行符&#xff1f; Java里面怎么樣得到平臺相關的換行符。我不可能到處都用"\n" 回答一 In addition to the line.separator property, if you are using java 1.5 or later and the String.format (or other formatting me…

scrapy常用工具備忘

scrapy常用的命令分為全局和項目兩種命令&#xff0c;全局命令就是不需要依靠scrapy項目&#xff0c;可以在全局環境下運行&#xff0c;而項目命令需要在scrapy項目里才能運行。一、全局命令##使用scrapy -h可以看到常用的全局命令 [rootaliyun ~]# scrapy -h Scrapy 1.5.0 - n…

機器學習模型 非線性模型_機器學習:通過預測菲亞特500的價格來觀察線性模型的工作原理...

機器學習模型 非線性模型Introduction介紹 In this article, I’d like to speak about linear models by introducing you to a real project that I made. The project that you can find in my Github consists of predicting the prices of fiat 500.在本文中&#xff0c;…

NOIP賽前模擬20171027總結

題目&#xff1a; 1.壽司 給定一個環形的RB串要求經過兩兩互換后RB分別形成兩段連續區域,求最少操作次數(算法時間O(n)) 2.金字塔 給定一個金字塔的側面圖有n層已知每一層的寬度高度均為1要求在圖中取出恰好K個互不相交的矩形&#xff08;邊緣可以重疊&#xff09;,求最多可以取…