svg背景

A series of serendipitous connections started me thinking about using tiled SVG elements for background images, especially patterns inspired by movies.

一系列偶然的联系使我开始考虑将平铺的SVG元素用于背景图像 ,尤其是受电影启发的图案。

SVG is uniquely suited for this, being infinitely scalable and (when correctly written) very small and fast to load. This article will introduce the code for the patterns; in the next, I’ll talk about techniques you can use to make your own SVG background images.

SVG特别适合于此,它具有无限的可扩展性,并且(正确书写时)非常小且加载速度快。 本文将介绍模式的代码。 接下来,我将讨论可用于制作自己的SVG背景图像的技术。

超越无限 (To Infinity, and Beyond)

The first is the wallpaper pattern from Andy Davis’s room in Toy Story. In this version I’ve kept the shading and code to a minimum:

首先是《 玩具总动员》中安迪·戴维斯(Andy Davis)房间的墙纸图案。 在此版本中,我将阴影和代码降至最低:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 413 254.2"><path fill="#FFF" d="M6,239.9c18.7,0,184.7,0.7,204.7,0s13.3-18.7-17.3-19.3c31.3-14.7,28.7-79.3-8.7-64.7 c8.7-79-128.7-76-93.8,24.7c-12.2,0-39.5,15.3-31.5,38.7c-17.3,2.7-30,2.4-42.8,6.2C1.9,229.7,6,239.9,6,239.9z"/><path fill="#FFF" d="M310.7,97.4c0,0,60.1,0.2,80.1,0c20.5-0.2,22.9-10.6,2.9-14.8C418.2,46.8,356,4.1,344.5,59
c-16.8-8.3-30.3,16.6-28.8,26c-6.7-0.5,0-1.3-9.3-0.5C297,85.3,289.4,97.8,310.7,97.4z"/>
</svg>

The SVG consists of two cloud-paths, drawn in Adobe Illustrator; the background has been left clear for maximum adaptability. Saved as andy-clouds.svg, the file can be used like this:

SVG包含两个在Adobe Illustrator中绘制的云路径; 为了最大的适应性,背景被清除了。 andy-clouds.svgandy-clouds.svg ,该文件可以这样使用:

body {background-image: url(andy-cloud.svg), linear-gradient(#00f,#33f);background-repeat: repeat, no-repeat;background-size: 200px 100px, cover;
}
Fig. 1: Vector tile for Overlook pattern
图1:用于忽略模式的矢量图块

Note that background-size determines the tiling of the cloud patterns, and that it roughly matches the aspect ratio of the SVG viewport.

请注意, background-size决定了云图案的平铺方式,并且它与SVG视口的纵横比大致匹配。

所有工作都没有玩 (All Work and No Play)

The next version is a little more complex, as it’s a continuous pattern from edge to edge that must tile seamlessly across the element it is applied to. In Illustrator, the drawing appears like the image in Figure 1; again, the background has been left clear and the code minimized as much as possible:

下一个版本稍微复杂一点,因为它是一个从一端到另一端的连续模式,必须在其所应用的元素上无缝平铺。 在Illustrator中,绘图的外观类似于图1中的图像。 同样,背景保持清晰,并尽可能减少代码:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 340.6 491.8"><polygon fill="#8C1A1E" points="229.9,208.7 170.5,243 111,208.7 111,140 170.5,105.7 229.9,140 "/><polygon fill="#8C1A1E" points="0,305.3 59.5,339.6 59.5,408.3 0,442.6 "/><polygon fill="#8C1A1E" points="342.8,442.6 283.3,408.3 283.3,339.6 342.8,305.3 "/><polygon fill="#D05427" points="91.6,0 0,52.9 0,0 "/><polygon fill="#D05427" points="340.6,0 340.6,52.9 248.8,0 "/><polygon fill="#D05427" points="21.4,264.6 102.8,311.6 102.8,431.7 -1.2,491.8 0,544.5 149.7,458.1 149.1,285.1 68.2,236.7
68.2,116.6 172.2,56.5 276.2,116.6 276.2,236.7 192.5,285 192.5,337.1 192.5,337.1 192.5,458.1 342.2,544.5 341,491.8 237,431.7 237,311.6 320.8,263.3 320.8,90.2 171.1,3.8 21.4,90.2 "/>
</svg>

Applying the pattern is also slightly more complex: the background-size of the applied image must match the aspect ratio of the SVG viewport exactly to create a seamless tile.

应用图案也稍微复杂一点:所应用图像的background-size必须与SVG视口的长宽比完全匹配才能创建无缝图块。

body {background-color: #000;background-image: url(overlook-carpet.svg);background-size: 169px 244px;
}
Did you know these two patterns are related? The Overlook carpet appears on the floor of Sid Phillip’s house in

Toy Story.

玩具总动员》中席德·菲利普(Sid Phillip)房屋的地板上。

While the SVG file is tiny (just 844 bytes before GZipping), what kills page loading time in many cases is not file size, but latency: the time taken to establish a new connection in order to download another file. To avoid that extra HTTP request, the SVG could be base-64 encoded or inlined. If inlined, the code would look like this:

尽管SVG文件很小(在GZipping之前只有844个字节),但在许多情况下,杀死页面加载时间的不是文件大小,而是等待时间:建立新连接以下载另一个文件所花费的时间。 为了避免额外的HTTP请求,SVG可以使用base-64编码或内联。 如果内联,则代码如下所示:

body {background-color: #000;background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 340.6 491.8"><polygon fill="#8C1A1E" points="229.9,208.7 170.5,243 111,208.7 111,140 170.5,105.7 229.9,140 "/> ... </svg>');background-size: 169px 244px;
}

Of course, that has the downside of increasing the size of the CSS file; ultimately, the best course of action will depend on several factors, including just how the SVG background will be used.

当然,这样做有增加CSS文件大小的缺点。 最终,最佳的行动方案将取决于几个因素,包括SVG背景的使用方式。

It’s also useful to note that changing the background-size of the image will change the tiling, sometimes in dramatic ways; for example, using background-size: 400px 244px will produce a result that looks like Figure 2:

还需要注意的是,更改图像的background-size会改变拼贴,有时会以戏剧性的方式进行。 例如,使用background-size: 400px 244px将产生如图2所示的结果:

Figure 2: Different background effects from adjusted size
图2:调整后的大小会产生不同的背景效果

There’s much more that can be done here, including the possibilities of animating the background images. In the meantime, I’d like to ask: what iconic textures from movies would you like to see as SVG backgrounds? Please leave your suggestions in the comments section below!

在这里可以做更多的事情,包括对背景图像进行动画处理的可能性。 同时,我想问: 想从电影中看到什么标志性的纹理作为SVG背景? 请在下面的评论部分中留下您的建议!

Veerle Pieters has an excellent tutorial on making the Overlook Hotel carpet pattern using Illustrator.

Veerle Pieters有一个出色的教程,介绍如何使用Illustrator制作Overlook Hotel地毯图案 。

翻译自: https://thenewcode.com/1008/SVG-Movie-Backgrounds-Andys-Room-and-Overlook-Hotel

svg背景

svg背景_SVG电影背景:安迪的房间,俯瞰酒店相关推荐

  1. SVG排版教程 | 样式背景属性详解与应用

    <元素属性原理详解与应用>讲到了SVG元素viewBox属性的实际应用,能够实现SVG元素在不同手机上的自适应适配(SVG元素的宽高根据手机屏幕大小等比例放大或缩小).SVG黑科技排版的每 ...

  2. html5 背景 svg,HTML5 SVG生成图案花纹背景样式的js插件

    Textures.js是一款非常实用的HTML5 SVG生成图案花纹背景样式的js插件.该js图案花纹背景插件基于d3.js,可以生成各种SVG图案花纹背景.这些图案包括各种线条.圆点.网格等,你甚至 ...

  3. HTML背景墙上加图标,背景墙挂件—背景墙上放一些什么挂件好

    在我们的背景墙上,我们肯定会放置一些好看的挂件,这样可以让我们的背景墙有一个更好的装饰效果,那到底要放置什么才能达到比较好的效果呢?小编今天就来为大家介绍下适合放置背景墙的一些挂件. 背景墙挂件 背景 ...

  4. CSS 背景(background)(背景颜色color、背景图片image、背景平铺repeat、背景位置position、背景附着、背景简写、背景透明、链接导航栏综合案例)

    1. 背景颜色(color) background-color:颜色值; 默认的值是 transparent 透明的 示例代码: <!DOCTYPE html> <html lang ...

  5. 背景颜色及背景图片相关的属性

    1.background-color 设置背景颜色,取颜色值 注意: 1.所有元素默认的背景颜色都是透明色,新建窗口的白色不是body的背景色,是浏览器渲染的 2. 背景颜色从边框位置开始绘制 3. ...

  6. CSS中背景颜色、背景图片、渐变色、背景定位、精灵图(雪碧图)介绍

    背景background: 背景可以设置为颜色和图片,设置为图片时,可以对图片继续设置. background-color:设置背景颜色: 其颜色的取值方式前面提到过,和color的取值一样,但是默认 ...

  7. android textview 背景图片,Android—TextView 背景颜色与背景图片设置

    Android TextView 背景颜色与背景图片设置,android textview 控件,android textview 背景, android textview 图片,android te ...

  8. CSS实现背景透明而背景上的文字不透明

    在我们设计制作一些网页的时候可能会用到半透明的效果,首先我们可能会想到用PNG图片处理,当然这是一个不错的办法,唯一的兼容性问题就是ie6 下的BUG,但这也不困难,加上一段js处理就行了.但假如我们 ...

  9. android textview获取背景颜色,Android TextView背景颜色与背景图片设置

    Android TextView 背景颜色与背景图片设置,android textview 控件,android textview 背景, android textview 图片,android te ...

最新文章

  1. 39.拖曳排序插件——sortable
  2. 开发日记-20190829 关键词 读书笔记《Unix环境高级编程(第二版)》DAY 5
  3. qpython手机版-qpythonl app下载
  4. python学习笔记:(三)list(列表)常用的内置方法
  5. EOS 智能合约源代码解读 (11)wrap合约“action_wrapper类”
  6. 模拟N场比赛理解自顶向下的程序设计思维
  7. 《javaScript100例|03》自写javaScript+CSS轮显效果
  8. UE4 HTC VIVE - 番外篇 - 局域网联机(一)
  9. android编程fragment,详解Android中Fragment的两种创建方式
  10. DEDE留言板调用导航的方法
  11. SAP License:SAP不便解决的问题之九——客户退货维修
  12. java 位运算 hashcode_hashcode面试题
  13. 编程实现二叉树的遍历
  14. L298N模块驱动电机(实现pwm调速)
  15. centos6 yum源失效解决方法
  16. 删除Linux虚拟机中的/dev/sdb磁盘步骤
  17. Swift——自定义转场动画(一)
  18. 【LWIP】原始套接字(SOCK_RAW)
  19. 回家的票抢上了吗?聊聊12306为什么时不时要崩一下
  20. python专场——暴力破解(DVWA)

热门文章

  1. AE-预览的时候出现FPS非实时-解决办法
  2. python 打印直角三角形
  3. 算法手撕代码66~70
  4. 自动升降压5-40V多串超级电容充电芯片和解决方案
  5. ZigBee的无线通信与网络组建
  6. 最全消费者防坑手册:走过最长的路,就是商家的套路
  7. 《马伯庸笑翻中国简史》
  8. java祖冲之加密算法_对称加密和非对称加密
  9. 第一次做项目经理总结_华为项目经理必备技能
  10. creo4.0 二维图转pdf