svg动画制作_制作第一个SVG动画

svg动画制作

Story of a designer trying to code animations instead of asking a dev to figure it out.

一位设计师尝试编写动画代码而不是要求开发人员弄清楚动画的故事。

编码动画是Webdesign的未来 (Coded animations are the future of Webdesign)

Because we have access to great tools like Principle, After effect, and others, we tend to imagine and make animations as gifs or videos. They are great because we have visual control over them.

因为我们可以使用诸如Principles,After Effects之类的出色工具,所以我们倾向于将动画想象成gif或视频。 它们很棒,因为我们可以对其进行视觉控制。

The challenge of Webdesign and web-based applications is that we need the content to be lightweight to get a faster loading.

Web设计和基于Web的应用程序所面临的挑战是,我们需要内容轻巧才能更快地加载。

Just like we started to convert our static illustrations into SVG code we can convert our gifs into SVG code! And this saves a tremendous amount of space.

就像我们开始将静态插图转换为SVG代码一样,我们也可以将gif转换为SVG代码! 这样可以节省大量空间。

If you don’t want to code they are already tools out there for you

如果您不想编码,那么它们已经为您提供了工具

Some of the most popular products today are the combination of After effect and Lottie or SVGator. These are really powerful and if you want to do complex animation I would definitely recommend them.

今天,一些最受欢迎的产品是After effect和Lottie或SVGator的组合。 这些功能真的很强大,如果您想进行复杂的动画,我绝对会推荐它们。

Their only downside is that they cost money and could be somewhat hard to understand.

他们唯一的缺点是他们要花钱,可能有点难以理解。

But it’s possible to animate stuff without fancy expensive software, you can do it only armed with your strength of problem-solving and determination. Learning the code in the back-end will help you make better animation as you will understand what is happening on a deeper level.

但是,可以在没有花哨的昂贵软件的情况下对事物进行动画处理,而只有凭借解决问题的能力和确定性,您才能做到。 学习后端的代码将帮助您制作更好的动画,因为您将更深入地了解正在发生的事情。

Here are 2 free tools you can use today to make your SVG animations:_Figma, to make the illustration._Visual Studio Code, to make the animation.

以下是您今天可以使用的2个免费工具来制作SVG动画:_ Figma ,来制作插图。_Visual Studio Code ,来制作动画。

Yes, I always go for the free stuff ;-)

是的,我总是去买免费的东西;-)

SVG和动画简介 (Introduction to SVG and animation)

An SVG is a file that contains code as an instruction about how something should be displayed on a screen. Because an SVG is only made of code you could have it done directly inside your HTML page, we tend to avoid that because your file would quickly become messy.

SVG是一个文件,其中包含代码,用于指示如何在屏幕上显示某些内容。 由于SVG仅由代码组成,因此您可以直接在HTML页面中完成它,因此我们倾向于避免这种情况,因为您的文件很快就会变得混乱。

This is the general structure of an SVG:

这是SVG的一般结构:

<svg><object1 "definition of this object" /><object2 "definition of this object" /></svg>

Important to notice is that an SVG is created by reading from top to bottom which means the object 1 is going to be built first and the object 2 is going to be built after on top of object 1.

需要注意的重要一点是,SVG是通过从上至下读取来创建的,这意味着将首先构建对象1,然后在对象1之上构建对象2。

As designers, we have to think objects are in the reverse order of what we are used to seeing.

作为设计师,我们必须认为对象与我们过去所看到的相反。

This is what we are going to do:

这是我们要做的:

<svg><object "definition of this object" ><animate "do a bunch of cool stuff please" /></object></svg>

The easiest way to get started is to open the object and code the animation we want directly inside of it.

最简单的入门方法是打开对象并将代码直接编码在其中。

An experienced developer would separate animation and object and use the reference link to target what they want. A more modern way to think animation in SVG is to think about all the elements that will behave the same way inside the website and code the animation directly in the CSS spreadsheet and target multiple objects in multiple SVG files.

有经验的开发人员可以将动画和对象分开,并使用参考链接来定位他们想要的对象。 在SVG中思考动画的一种更现代的方法是考虑网站内所有行为相同的元素,并直接在CSS电子表格中编码动画,并针对多个SVG文件中的多个对象。

Today we just want to get started

今天我们只想开始

充分利用Figma的技巧 (A tip to get the best of Figma)

After trying sketch and what Adobe illustrator I went to the conclusion that Figma what the best to extract a clean SVG code.

在尝试了草图和Adobe illustrator之后,我得出了这样的结论:Figma最好是提取干净的SVG代码。

Even better, they added an extra feature to also extract the “name” you defined as “id” inside the SVG.

更好的是,他们添加了一项额外功能,也可以在SVG内部提取您定义为“ id”的“名称”。

Here is how to do it:

这是操作方法:

Image for post
Enable the SVG “id” Attribute feature of Figma to get an SVG file with the name of the elements you have designed
启用Figma的SVG“ id”属性功能,以获取具有您设计的元素名称的SVG文件

获取有关动画的文档的最佳位置 (The best place to get documentation about animation)

In this tutorial, I will mostly use the basic of what is called “SMIL” animation, you can always find more information on CSS-tricks.

在本教程中,我将主要使用所谓的“ SMIL”动画的基础,您始终可以找到有关CSS技巧的更多信息。

An interesting point is you will find the syntax can change because I am writing CSS animation directly inside of the HTML SVG file and it is possible to write the animation on a CSS file with the CSS syntax.

有趣的一点是,您会发现语法可以更改,因为我直接在HTML SVG文件内部编写CSS动画,并且可以使用CSS语法在CSS文件上编写动画。

最后一招,您可能想要使用面具并注意它不起作用。 (One last trick, you might want to use a mask and notice that it doesn’t work.)

In an SVG animation, the objects inside a mask property can’t be animated.You will have to use a feature called “clip-path”

在SVG动画中,无法对mask属性内的对象进行动画处理。您将必须使用称为“剪切路径”的功能

Image for post

In Figma, it’s pretty simple, instead of using the Mask feature you can use the “Clip content” feature for any group that you have created.

在Figma中,这非常简单,您可以对创建的任何组使用“剪辑内容”功能,而不必使用“蒙版”功能。

Figma will them automatically write a nice SVG file that you can play with.

Figma将自动为他们编写一个不错的SVG文件,供您播放。

Alright, now that we have done this let’s get to it. ;-)

好吧,既然我们已经做到了,那就开始吧。 ;-)

步骤1:以线性运动加载 (Step 1: load with a linear movement)

JeremieJeremie的液体装载

The trick to making stuff move is to use a framework called “AnimateTransform” and an instruction called “Translate”.

使内容移动的技巧是使用一个名为“ AnimateTransform”的框架和一个名为“ Translate”的指令。

translate” will indicate that we want an object to move.

平移 ”将表示我们希望物体移动。

will assign to our object some “values” to indicate the coordinate of where the object should start and go to.

将为我们的对象分配一些“ ”,以指示对象应开始和到达的位置的坐标。

We write the values as follow:0,0 = Top,Left ; = separator to the next coordinate-60,40 = go 60 pixel down, go 40 pixel right

我们写的值如下: 0,0 = Top,Left; =下一个坐标的分隔符60,40 =向下移60像素,向右移40像素

We can also indicate a “dur” for the duration and “indefinite” “repeatCount” to control our animation.

我们还可以在持续时间内指定“ dur ”,并在动画中指定不确定 ”“ repeatCount ”。

<object ><animateTransformattributeName="transform"attributeType="XML"type="translate"dur="1.5s"values="0,0;-60,0"repeatCount="indefinite"/></object>

You can make any shape and try to move them on the screen just like I did.

您可以制作任何形状,然后像我一样尝试在屏幕上移动它们。

Step2:旋转游泳的鱼。 (Step2: the rotating swimming fish.)

Jeremie耶雷米游泳鱼

They are different ways to create a swim but the quickest is to a command called “rotate” which is also supported by the “AnimateTransform” framework.

它们是创建泳姿的不同方法,但最快的方法是调用“旋转”命令,“ AnimateTransform”框架也支持该命令。

Rotate” in an instruction that takes into consideration an angle and a coordinate for the centre of the rotation.

一条指令中的“ 旋转 ”,其中考虑了旋转中心的角度和坐标。

Important: you will need to specify the centre of where your object must rotate from to get the right rotation.

重要提示:您需要指定对象必须旋转的中心才能获得正确的旋转。

We write the values as follow:0 0 0 = “0 deg rotation” “rotate from top corner” “rotate from left corner”; = separate the values

我们将值写为: 0 0 0 =“ 0度旋转”“从上角旋转”“从左角旋转”; =分隔值

<object ><animateTransformattributeName="transform"attributeType="XML"type="rotate"dur="2s"values="-1.5 30 -10;1.5 30 -10;-1.5 30 -10"repeatCount="indefinite"/></object>

Note that here I indicated 3 coordinates as I would like my object to start with a -1.5 degree angle rotate to +1.5 and go back to -1.5.

请注意,在这里我指定了3个坐标,因为我希望我的对象从-1.5度角开始旋转到+1.5,然后回到-1.5。

Special trick: you can rotate an object with some property and then rotate a group with different properties.

特殊技巧 :可以旋转具有某些属性的对象,然后旋转具有不同属性的组。

You can also learn more about rotation and how to make a rotating loading with this tutorial:

您还可以通过本教程进一步了解旋转以及如何进行旋转加载:

DesignCourseDesignCourse的教程

第三步:灯塔背后的秘密 (Step3: the secret behind the lighthouse)

Jeremie杰里米的灯塔

There is a secret behind the lighthouse. In this example, this is not the light that is moving (something we could also do with a path change) but it’s the sky who is rotating around the light source.

灯塔后面有一个秘密。 在此示例中,这不是正在移动的灯光(我们也可以通过更改路径来做到这一点),而是围绕光源旋转的天空。

Trying things that are not straight forward really provide a chance to learn new techniques of animations.

尝试一些并非直截了当的事情确实可以提供学习动画新技术的机会。

This is how the scene is staged:

这是场景的上演方式:

Image for post
tips to think the rectangles in a lighthouse effect
在灯塔效果中考虑矩形的技巧

It’s okay if your animation is not perfect, mine is struggling too…This is really where we see the limits of animating directly in code, I had to slowly move might rotating values to get something somewhat acceptable.

如果您的动画不完美也可以,我的也很挣扎……这确实是我们看到直接在代码中设置动画的局限性的地方,我不得不慢慢移动可能旋转的值以获得某种可以接受的效果。

I would be curious to see how you solved this problem ;-)

我很想知道你是如何解决这个问题的;-)

步骤4:通过SVG路径进入太空 (Step4: go in space with SVG path)

Jeremie杰里米太阳能系统

Alright, now that we know the trick of the “AnimateTransform” framework it’s time you learn about the new cool stuff of “AnimateMotion”.

好了,现在我们知道了“ AnimateTransform”框架的诀窍,是时候学习“ AnimateMotion”的新功能了。

To get started we will do something simple, moving a circle along a path.

首先,我们将做一些简单的事情,沿着路径移动一个圆。

A circle is an object composed of a location coordinate “cx” and “cy” for the x and y axis and “r” for the size of its rayon.

圆是一个对象,由x和y轴的位置坐标“ cx”和“ cy”以及其人造丝的大小的“ r”组成。

<circle id="Venus" cx="10" cy="20" r="3" fill="#FC5FAB">

To animate this element we will indicate a “begin” time, state that the “fill” should be “freeze” to be maintained and a “path” along wich it should move.

动画这个元素,我们将指示“ 开始 ”的时候,国家的“ 填充 ”应该是“ 冻结 ”,以维持并沿至极应该移动“ 路径 ”。

<circle id="Venus" cx="0" cy="0" r="3" fill="#FC5FAB"><animateMotiondur="3s"begin="0"repeatCount="indefinite"fill="freeze"path="M-6 84.5C-6 84.5 7.5 65 30.5 65C53.5 65 66.5 84.5 66.5 84.5" /></circle>

notice that because I am asking a circle to move along a path in an animation I need to set up it’s coordinate (cx and cy) to “0” as they will be attached to the path coordinate.

请注意,因为我要让圆沿着动画中的路径移动,所以我需要将其坐标(cx和cy)设置为“ 0”,因为它们将附加到路径坐标上。

“AnimateMotion” is a different framework than “AnimateTransform” unfortunately if you try to combine them both you will run a jigsaw of almost uncontrollable animation.

不幸的是,“ AnimateMotion”和“ AnimateTransform”是一个不同的框架,如果您尝试将两者结合起来,则会运行几乎无法控制的动画拼图。

Fortunately, you can do all sorts of cool stuff with “AnimateMotion” too, you can learn about them here:

幸运的是,您也可以使用“ AnimateMotion”来做各种很酷的事情,您可以在这里了解它们:

This is pretty advanced stuff (that I don’t think I can even do), so you might want to take your time with this ;-)

这是相当高级的东西 (我什至认为我做不到), 所以您可能想花点时间;-)

你真棒! (You are AWESOME!)

You made it to here and hopefully tried some of these exercises, I bet you animation skills are getting to the rooftop. I can’t wait to see how you will integrate this new skill to your websites and solutions.

您到了这里,并希望尝试了其中的一些练习,我敢打赌,动画技能已经达到了顶峰。 我等不及要看您如何将这项新技能整合到您的网站和解决方案中。

Perhaps you will go even further and design complex animation with one of those programs I talked about in the beginning but if you do I hope you learn something useful about how it works in the back end.

也许您会更进一步,并使用我在开始时提到的其中一个程序来设计复杂的动画,但是如果您愿意的话,我希望您能学到一些有关动画在后端如何工作的有用信息。

翻译自: https://levelup.gitconnected.com/making-your-first-svg-animations-d79aad48f014

svg动画制作

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274970.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网站前端设计,从960框架开始

一个网站进入到前端设计阶段&#xff0c;第一步肯定是为全站搭建一个统一的&#xff0c;基础的HTML模型&#xff0c;在这里推荐一下我刚学习的960框架。960是一个CSS框架&#xff0c;你肯定在想&#xff0c;这个世界肯定是疯了&#xff0c;连CSS都有框架了吗&#xff0c;没错&a…

60+ 实用 React 工具库,助力你高效开发!

大家好&#xff0c;我是若川。持续组织了5个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。最近看到一些实用的…

2012年12月第二个周末

2019独角兽企业重金招聘Python工程师标准>>> 这周&#xff0c;装上了windows版的 Linux版的oracle 熟悉了下SQL*PLUS的编程规则&#xff0c;还有常用的linux命令 看了一本《简爱》 正在看oracle 转载于:https://my.oschina.net/u/204616/blog/545513

『C#基础』调用CMD的一个小工具

由于经常要使用CMD的一些命令&#xff0c;比如查看IP&#xff0c;Ping一个网址之类的。于是就写了一个调用CMD.exe的小工具。 主要就是实现这样一个事情&#xff1a;调用CMD.exe然后传给它我想要执行的命令&#xff0c;最后获取结果。 界面&#xff1a; 代码&#xff1a; 主要执…

小姐姐:如何参与大型开源项目-Taro 共建

大家好&#xff0c;我是若川。持续组织了5个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。“本文来自前端程序…

JavaWeb学习总结(十七)——JSP中的九个内置对象

2019独角兽企业重金招聘Python工程师标准>>> 一、JSP运行原理 每个JSP 页面在第一次被访问时&#xff0c;WEB容器都会把请求交给JSP引擎&#xff08;即一个Java程序&#xff09;去处理。JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet) &#xff0c;然…

C#网络编程(异步传输字符串) - Part.3[转自JimmyZhang博客]

源码下载&#xff1a;http://www.tracefact.net/SourceCode/Network-Part3.rar C#网络编程(异步传输字符串) - Part.3 这篇文章我们将前进一大步&#xff0c;使用异步的方式来对服务端编程&#xff0c;以使它成为一个真正意义上的服务器&#xff1a;可以为多个客户端的多次请求…

chrome黑暗模式_黑暗模式:如何克服黑暗面

chrome黑暗模式This article has been written by Redmadrobot Design Lab. Translated and reposted with permission by Alconost Inc., professional translation and localization company.本文由 Redmadrobot设计实验室 撰写 。 经过 专业翻译和本地化公司 Alconost Inc.的…

Deco 智能代码体验版正式上线啦,快来体验设计稿一键生成代码~

Deco 是什么&#xff1f;—Deco 智能代码项目是我们团队在「前端智能化」方向上的探索&#xff0c;其聚焦设计稿一键生成多端代码这一切入点&#xff0c;实现将 Sketch/Photoshop 等设计稿进行解析并直接生成多端代码&#xff08;Taro/React/Vue&#xff09;的能力。Deco 可以使…

平面设计和网页设计的规则_从平面设计到用户界面:这是您应该知道的最重要的规则

平面设计和网页设计的规则Maybe you’re here because you think UI Design is the future of Graphic Design. Maybe what motivates you is the money. Or maybe you just woke up one day and someone at work told you “So, you are a designer, right? Well, we need an…

即将到来的 ECMAScript 2022 新特性

大家好&#xff0c;我是若川。持续组织了5个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。ECMAScript 规范每…

设计类的五个原则_内容设计的5个原则

设计类的五个原则重点 (Top highlight)There are many heuristics and principles for creating good content. Some are created from a UX perspective, others from a content marketing point of view. They range from very long to very concise ones. I reviewed a larg…

Umi 4 RC 发布

大家好&#xff0c;我是若川。感谢大家一年以来的支持和陪伴。这一年疫情反复&#xff0c;年底应该有由于疫情不能回家的小伙伴。在这里先祝福大家&#xff0c;新年快乐。本打算今天不发文&#xff0c;但看到这篇觉得不错&#xff0c;就发一下。大家好&#xff0c;Umi 4 经过几…

figma下载_在Figma中将约束与布局网格一起使用

figma下载While doing research for the book “Designing in Figma”, I discovered a powerful way to lay out objects using a combination of Layout Grid and Constraints. The interface of Figma does not indicate a connection between the two, so it can be discov…

Java单元测试之JUnit4详解

2019独角兽企业重金招聘Python工程师标准>>> Java单元测试之JUnit4详解 与JUnit3不同&#xff0c;JUnit4通过注解的方式来识别测试方法。目前支持的主要注解有&#xff1a; BeforeClass 全局只会执行一次&#xff0c;而且是第一个运行Before 在测试方法运行之前运行…

我在黑暗中看到你眼中的月光_你好黑暗,我的老朋友

我在黑暗中看到你眼中的月光(Originally published on https://web.dev/prefers-color-scheme/.)(最初发布于https://web.dev/prefers-color-scheme/ 。) 介绍 (Introduction) &#x1f4da; I have done a lot of background research on the history and theory of dark mod…

Element Plus 正式版发布啦!

大家好&#xff0c;我是若川。祝大家新年快乐&#xff0c;开工大吉。公众号回复「红包」可以领取源码共读红包封面。持续组织了6个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时…

大型网站技术架构(一)大型网站架构演化

2019独角兽企业重金招聘Python工程师标准>>> 看完了有一本书&#xff0c;就应该有所收获&#xff0c;有所总结&#xff0c;最近把《大型网站技术架构》一书给看完了&#xff0c;给人的印象实在深刻&#xff0c;再加上之前也搞过书本上讲的反向代理和负载均衡以及ses…

永不示弱_永不过时的网页设计:今天和2000年的在线投资组合

永不示弱重点 (Top highlight)Philippe Starck, a renowned industrial designer, once said:著名的工业设计师Philippe Starck曾经说过&#xff1a; “A designer has a duty to create timeless design. To be timeless you have to think really far into the future, not …

如何使用 React 创建一个作品集网站

大家好&#xff0c;我是若川。持续组织了6个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。今天&#xff0c;你…