svg动画制作

I've been reading David Walsh's blog for years. The tips and tutorials he shares have helped me fix a lot of problems. I love that I get to support him now by advertising TrackJS on his site. Plus, I get a chance to build some cool SVG animations!I'm not a designer or a marketer by trade. I'm a software developer, but as an entrepreneur I end up doing a bit of everything. I spent a lot of time sketching and googling to figure out how this works. I'd like to share what I've learned about designing and building animated SVG ads, like this one right here:

多年来,我一直在阅读David Walsh的博客。 他分享的技巧和教程帮助我解决了许多问题。 我喜欢现在通过在他的网站上投放TrackJS来支持他。 另外,我有机会制作一些很酷的SVG动画!我不是行业的设计师或营销商。 我是一名软件开发人员,但是作为一名企业家,我最终做了很多事情。 我花了很多时间进行素描和谷歌搜索来弄清楚它是如何工作的。 我想分享一下我在设计和制作SVG动画广告时所学到的知识,就像下面这样:

SVG的优势 (Advantages of SVG)

SVG, or Scalable Vector Graphic, an XML-based structure that defines the shapes, lines, and colors of an image in such a way that it can be viewed at any size and still retain a crisp look. SVG is not well suited to display photography images, but it is excellent for drawings, text, and shapes.

SVG或可伸缩矢量图形,这是一种基于XML的结构,它定义了图像的形状,线条和颜色,从而可以以任何大小查看它并保持清晰的外观。 SVG不太适合显示摄影图像,但是它非常适合绘制图形,文字和形状。

It is also a fantastic platform for animations, as the same CSS technologies that drive animation on the web can also animate the markup for SVGs.

它也是一个很棒的动画平台,因为在网络上驱动动画的相同CSS技术也可以为SVG标记添加动画。

SVG images are well supported by web browsers today, although Internet Explorer 9 and earlier may have some problems (big surprise).

如今 ,尽管Internet Explorer 9和更早版本可能存在一些问题(令人惊讶),但Web浏览器很好地支持SVG图像 。

规格 (The Spec)

David gave us a standard banner spot at the top of content. The ad should be responsive from mobile to desktop sizes, up to the standard banner dimensions of 728px by 90px.

大卫在内容顶部为我们提供了一个标准的横幅广告。 广告应在移动设备尺寸和台式机尺寸之间做出响应,最大标准横幅尺寸为728px x 90px。

Our ad needs to quickly describe TrackJS and how we can help. We monitor your JavaScript for bugs and give you awesome error reports when they happen. We need to figure out a way to say this concisely and with a bit of humor.

我们的广告需要快速描述TrackJS以及我们如何提供帮助。 我们会监控您JavaScript中的错误,并在发生错误时为您提供出色的错误报告。 我们需要找到一种简洁而又幽默的说法。

We also need to be a responsible advertiser:

我们还需要成为负责任的广告客户:

  1. Clearly differentiate from the page.
    与页面明显区分开。
  2. Do not block or slow the content from loading.
    不要阻止或减慢内容的加载速度。
  3. Do not distract the visitor from the content.
    不要分散访问者的注意力。
View Demo观看演示

我的第一个动画广告 (My First Animated Ad)

I wanted to build something that plays off of "bugs". We had some Adobe Illustrator assets of a bug getting squashed for an earlier sticker that we can probably reuse. Maybe the bugs can fly over the ad and get squashed by the "free trial" button.

我想构建一些可以消除“错误”的东西。 我们压缩了一些Adobe Illustrator资产,以便减少一个错误,以便我们可以重新使用较早的标签。 这些错误可能会飞过广告,并被“免费试用”按钮压倒。

I started fumbling my way around the internet to figure out how to make this happen. I defined an SVG element in an HTML file and started learning. I set the height and width for the banner. Double that for the viewBox, which is like the window into the drawing, so that everything looks sharp on high-density displays.

我开始在互联网上摸索,弄清楚如何做到这一点。 我在HTML文件中定义了SVG元素并开始学习。 我设置横幅的高度和宽度。 将viewBox的尺寸加倍,就像进入图形中的窗口一样,以便在高密度显示器上一切看起来都很清晰。

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="720px" height="90px" viewBox="0 0 1456 180" style="background-color:#2c3237"></svg>

And now I had a nice grey box! Small accomplishments.

现在我有了一个漂亮的灰色盒子! 小成就。

Most of the ad was going to be static: our logo, description, and tagline. I drew those with Photoshop in the fonts and colors I wanted and exported it as an SVG. I copied the shape definitions that came out of that and pasted it into my SVG element as a new path.

大多数广告都是静态的:我们的徽标,说明和标语。 我用Photoshop用我想要的字体和颜色绘制了这些内容,然后将其导出为SVG。 我复制了其中的形状定义,并将其作为新路径粘贴到我的SVG元素中。

I made a button too, but I exported that as a separate SVG so that I could manipulate it separately later. I had something like this:

我也做了一个按钮,但是我将其导出为单独的SVG,以便以后可以单独操作。 我有这样的事情:

<svg xmlns="http://www.w3.org/2000/svg">
<path class="tjs-logo" d="..."/>
<path class="tjs-button" d="..."/>
</svg>

用CSS制作SVG动画 (Animating SVG With CSS)

Now to make some animations. I exported the bug animation from Adobe Illustrator as an SVG and grabbed the path data. I wanted to have a few bugs, but I didn't want to have multiple copies of the path data, as it was quite large. Fortunately, I found the SVG Symbol element, which lets us define shapes that can be instantiated many times. Just what I needed.

现在制作一些动画。 我从Adobe Illustrator中将错误动画导出为SVG,并获取了路径数据。 我想要一些错误,但是我不想拥有路径数据的多个副本,因为它非常大。 幸运的是,我发现了SVG Symbol元素,该元素使我们可以定义可以实例化多次的形状。 正是我所需要的。


<defs>
<symbol id="tjs-bug">
<g class="tjs-bug">
<path d="..." />
<path d="..." />
<path d="..." />
</g>
</symbol>
</defs>

Symbols get instantiated with the <use> element, which I created three of. I added a transform to each of them to reduce them down to 0% size so that they wouldn't be visible on the page right away.

符号由<use>元素实例化,我创建了三个元素。 我为每个按钮添加了一个转换,以将其缩小到0%,这样就不会在页面上立即显示它们。


<use class="tjs-bug-1" xlink:href="#tjs-bug" transform="scale(0)" />
<use class="tjs-bug-2" xlink:href="#tjs-bug" transform="scale(0)" />
<use class="tjs-bug-3" xlink:href="#tjs-bug" transform="scale(0)" />

I'd done a few things with CSS Animations, so it was great that you can embed CSS directly inside the SVG markup. You just need to surround the rules with the CDATA syntax so that it continues to be valid XML (although most browsers are very forgiving of this).

我已经使用CSS动画完成了一些工作,因此可以将CSS直接嵌入SVG标记中非常好。 您只需要使用CDATA语法来包围规则,以使它继续是有效的XML(尽管大多数浏览器对此都是非常宽容的)。

I defined a CSS keyframe for each of the three bugs that had the bug "fly" across the ad. Using a midway stop point in the keyframe and the ease tween to make it feel like the bug stopped and landed before moving on. Then finally attached the keyframe to the class name on each use element.

我为三个错误中的每个错误定义了一个CSS keyframe ,这些错误在整个广告中“飞”起来。 在关键帧中使用中间的停止点并进行ease补间,以使其感觉像虫子在继续前进之前就停下来了。 然后最后将关键帧附加到每个use元素上的类名称。


<svg …>
<style type="text/css"><![CDATA[
@keyframes flight-1 {
0% {
transform: translate(-100px, -40px) scale(2.5) rotate(105deg)
}
66% {
transform: translate(500px, 0) scale(2.5) rotate(85deg)
}
100% {
transform: translate(1800px, -60px) scale(2.5) rotate(85deg)
}
}
.tjs-bug-1 {
animation: 1.8s flight-1 1s forwards ease;
transform: scale(0)
}
]]></style> <...> </svg>

I used the same flow to export a bug squash drawing from Adobe Illustrator and add it to the SVG. I timed another keyframe animation to have it appear and grow just as the button slides down from the top. The whole thing happens fast enough that it feels like the button squashes one of the bugs.

我使用相同的流程从Adobe Illustrator导出错误南瓜图,并将其添加到SVG。 我为另一个关键帧动画设置了时间,使其随着按钮从顶部向下滑动而出现并增长。 整个过程发生得足够快,以至于感觉到按钮消除了其中一个错误。

Here's the final result from it. This version below is not minified or obfuscated, so you can pop-open your dev tools and see all the details of the final implementation.

这是它的最终结果。 以下版本未精简或混淆,因此您可以弹出您的开发工具并查看最终实现的所有详细信息。




















下一代 (The Next Generation)

Building the first one was a lot of fun, and I learned a lot about SVGs along the way. This ad has been running for several months but now it's time for an update. This time, I wanted to tell a story that recognizes that JavaScript creeps into our apps in all sorts of unexpected ways, and when it fails it can have nasty consequences. JavaScript Happens.

构建第一个非常有趣,而且我在此过程中学到了很多有关SVG的知识。 这则广告已经投放了几个月,但现在该更新了。 这次,我想讲一个故事,该故事认识到JavaScript会以各种意想不到的方式渗入我们的应用程序,而当JavaScript失败时,可能会带来不良后果。 JavaScript发生了。

<object data="animated-happens.svg" type="image/svg+xml" style="width:100%;pointer-events:none;"></object>

For this ad, I worked with a talented illustrator to bring it to life. Spelunking through his code, I saw two important patterns that I had missed.

对于这则广告,我与一位才华横溢的插画家合作,使之栩栩如生。 通过他的代码,我看到了我错过的两个重要模式。

1.使用<animate>元素代替CSS (1. Using <animate> Elements instead of CSS)

Rather than using a large, embedded set of CSS rules to handle animating all the different elements, he included <animate> and <animateTransform> elements nested inside of the drawings to be animated. I can instantly see the utility of doing this, as I spent lots of time scrolling back and forth during my original development tweaking the timing.

他没有使用大量的嵌入式CSS规则来处理所有不同元素的动画,而是包括了嵌套在要动画的图形内部的<animate><animateTransform>元素。 我可以立即看到执行此操作的实用程序,因为在最初的开发过程中,我花了大量时间来回滚动调整时间。

Keeping the animation rules close to the objects to be animated is a huge win for productivity during the development, and any future maintenance that might be needed.

将动画规则保持在要动画的对象附近,这对于开发过程中的生产率以及将来可能需要的任何维护都是一个巨大的胜利。

2.将SVG引用为<object> (2. Referencing the SVG as an <object>)

Rather than including the SVG markup directly in the HTML document, as I had done, he had referenced an external SVG file using the <object> element. This allows for the SVG markup to be externally included and referenced in the DOM.

他没有像我所做的那样直接在HTML文档中包含SVG标记,而是使用<object>元素引用了一个外部SVG文件。 这允许SVG标记从外部包含并在DOM中引用。

<object data="animated-happens.svg" type="image/svg+xml"></object>



If we had referenced the SVG file using an <img> element instead, this creates a strict boundary between the SVG and the DOM. The implication of this is that the "load" event will not trigger after the SVG is loaded into cache, and the animation will only ever play once.

如果我们改用<img>元素引用了SVG文件,则会在SVG和DOM之间创建严格的边界。 这意味着在将SVG加载到缓存后,不会触发“加载”事件,并且动画只会播放一次。

View Demo观看演示

结语 (Wrapping Up)

SVG animations are cool. They load fast, have lots of powerful options, and are widely compatible. When used responsibly, we can use them to tell short, impactful stories, then get out of the user's way.

SVG动画很棒。 它们加载速度快,具有许多强大的选项,并且具有广泛的兼容性。 负责任地使用时,我们可以使用它们来讲述简短而有影响力的故事,然后摆脱用户的视线。

The web gets better every day. When it breaks, I'm so proud to be part of making it better and fixing its bugs. I'd love to help you too, grab a totally free, no credit card or anything, trial of TrackJS today.

网络每天都在变得更好。 当它崩溃时,我为能更好地改进它和修复其错误而感到自豪。 我也想为您提供帮助,立即获得TrackJS的完全免费,无需信用卡或其他任何服务。

翻译自: https://davidwalsh.name/building-animated-svg-banners

svg动画制作

http://www.taodudu.cc/news/show-5096383.html

相关文章:

  • css如何制作横幅,如何在CSS中添加顶级横幅而无需触摸或添加任何HTML div?
  • css如何制作横幅,javascript-仅使用CSS的标题横幅?
  • css如何制作横幅,程序员使用CSS3的创建网站横幅
  • css如何制作横幅,基本的CSS横幅
  • 6.《练习:vue之用指令制作横幅》
  • 解析 ETH 区块数据交易input
  • ETH Geth节点配置参数
  • ETH2.0:Altair 升级
  • ETH-服务节点部署(全网最新)
  • 48_通过接口获取以太坊最新区块高度
  • 以太坊区块浏览器怎么使用_使用以太坊专用网络管理器Puppeth
  • 台历设计的注意点
  • 【小知识】PCB线路板的打样过程
  • PCB完整加工过程
  • 6 海康视觉平台VisionMaster 上手系列:常用工具(三)
  • ZEMAX | 如何使用 OpticStudio 设计车标投影系统 Ⅰ
  • ZEMAX | 如何使用 OpticStudio 设计车标投影系统 Ⅱ
  • 高精度测绘行业玻璃码盘 伺服电机玻璃码盘 编码器码盘定制
  • 一种简化的线扫相机单维度标定法
  • VS2017使用GSL
  • Windows VS2017使用GoogleTest
  • vs2017 c语言操作界面,Visual Studio 2017安装和使用教程(详细)
  • 【visual studio 2017】基本使用过程,新手教学
  • ROS参数服务器(参数使用详细介绍)
  • 2.3 参数服务器
  • 逻辑斯蒂回归(逻辑回归)Python简单实现(算法笔试)
  • 《PyTorch深度学习实践》06 逻辑斯蒂回归 代码
  • scikit-learn 中逻辑斯蒂回归的使用
  • 机器学习之逻辑斯蒂回归
  • 逻辑斯蒂回归模型——逻辑斯蒂分布、二项逻辑斯蒂回归模型、参数估计与多项逻辑斯蒂回归

svg动画制作_制作动画SVG横幅相关推荐

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

    svg动画制作 Story of a designer trying to code animations instead of asking a dev to figure it out. 一位设计 ...

  2. fiash星空动画制作_三维动画制作的详细流程

    三维动画制作的详细流程: 随着互联网的发展,三维动画技术更新,三维动画制作技术在生活中运用十分广泛,我们经常在一些电视广告,影视电影中会看到一些三维特效,因为震撼的真实感很受大众喜欢.三维动画技术让视 ...

  3. 安卓动画入门_网络动画入门

    安卓动画入门 无论您是刚刚开始使用基础知识还是想探索更高级的技术,我们已经构建了完整的指南来帮助您学习CSS和为CSS 设置动画 . 网络动画入门 近年来,Motion已成为Web设计领域中非常重要的 ...

  4. svg标签和svg文件区别_什么是SVG文件? SVG图片和标签说明

    svg标签和svg文件区别 SVG (SVG) SVG or Scalable Vector Graphics is a web standard for defining vector-based ...

  5. img 加载 svg占位符_如何使用SVG作为占位符以及其他图像加载技术

    img 加载 svg占位符 by José M. Pérez 由JoséM.Pérez 如何使用SVG作为占位符以及其他图像加载技术 (How to use SVG as a Placeholder, ...

  6. 关节动画概念_核心动画概念:预期和贯彻

    关节动画概念 We can create more realistic CSS animations on our pages by using principles established by c ...

  7. 简单的网页制作_制作简单网页物体

    在掌握了路径和图层样式之后,我们终于可以开始"白手起家"地制作网页了.这不同于以往开启一幅图像后对其进行调整,或将两个图层通过蒙版或图层混合模式进行合成等操作,是完全在一片空白上逐 ...

  8. 电子琴节奏包制作_制作MIDI电子音乐离不开的三件“法宝”

    现在越来越多的年轻人开始对MIDI制作感兴趣,特别是随着电脑的高速发展,原来离普通人很遥远的专业设备可以用软件代替,这无疑是音乐爱好者的福音,体验一下自己当音乐制作人的乐趣吧! 那么什么是MIDI呢? ...

  9. 电子琴节奏包制作_制作MIDI电子音乐需要准备些什么?

    现在越来越多的年轻人开始对MIDI制作感兴趣,特别是随着电脑的高速发展,原来离普通人很遥远的专业设备可以用软件代替,这无疑是音乐爱好者的福音,体验一下自己当音乐制作人的乐趣吧! 那么什么是MIDI呢? ...

最新文章

  1. java oracle exp_java中使用oracle的exp/imp导出、导入数据
  2. 什么才是软件开发的葵花宝典?
  3. python进行矩阵计算公式_纯python进行矩阵的相乘运算的方法示例
  4. python列表根据值找索引_python实现列表中由数值查到索引的方法
  5. 不会Python爬虫?教你一个通用爬虫思路轻松爬取网页数据,赶紧收藏!!
  6. 基于python和opencv的人脸识别
  7. 【Flink】Flink 清理过期 Checkpoint 目录的正确姿势
  8. 如何保证进程间同步工作_系统设计硬核知识(2)——操作系统的进程管理
  9. MTK平台修改分区大小之后,通过fastboot工具烧录的说明
  10. LVS/NAT的配置和应用
  11. HarmonyOS开源第三方组件 —— B站开源弹幕库引擎的使用
  12. 安装Google play 服务等四件套
  13. 旅游网站毕业设计,旅游网站网页设计设计源码,旅游网站设计毕业论文
  14. 如何把PDF转Word?建议收藏这些方法
  15. mysql连接查询分为几种方式_SQL多表查询的几种连接方式
  16. RSA2048签名和加密+OAEP填充方式(前端)
  17. 三、SALV 添加自定义的状态栏
  18. 人脸识别的最新进展以及工业级大规模人脸识别实践探讨
  19. 流行的物联网通信协议回顾
  20. 张慧勇:迅雷链在解决高性能之后,都在研究这些……

热门文章

  1. 二、C语言的数据类型—整型数据
  2. wlan-cloud-ucentral docker 服务器部署
  3. Python飞机大战实例有感——pygame如何实现“切歌”以及多曲重奏?
  4. 从某网站下载MP3的例子
  5. 计算机监控通信网络 rs485和rs232,一文详解RS232和RS485的区别之处
  6. 爬虫-获取百度图片壁纸保存至本地
  7. 第五次Scrum Meeting
  8. TCP实现之:TCP报文接收
  9. R型低频变压器和高频变压器有什么不一样?
  10. 计算组合数公式nCr的实现方法和源代码