css3d转换

“Cinemagraphs” are animated photographs that feature repeated and subtle movement. Early experiments by Kevin Burg and Jamie Beck in fashion photography led to the format’s modern popularity.

“电影摄制”是具有重复和微妙动作的动画照片。 凯文·伯格(Kevin Burg)和杰米·贝克(Jamie Beck)早期在时尚摄影中进行的实验导致了这种格式在现代的流行。

But GIFs - the usual source for cinegraphs - aren’t a video format, and can’t be controlled very well. In addition, creating a true cinemagraph can require a lot of work. Over the weekend I realized that for some images the same effect could be created using CSS 3D transforms. As an alternative to the expense of shooting full video, this could be a valuable, performant and efficient technique for product demos and visualizations.

但是GIF(通常是电影的来源)不是视频格式,因此无法很好地控制。 另外,创建真实的电影胶片可能需要大量工作。 整个周末,我意识到对于某些图像,可以使用CSS 3D变换来创建相同的效果。 除了拍摄完整视频的费用以外,这对于产品演示和可视化可能是一种有价值,高效且有效的技术。

搭建舞台 (Setting The Stage)

We start with the still portion of the image: in this case I’ve used a photograph from the previously mentioned startupstockphotos, used as a background in a div:

我们从图像的静止部分开始:在这种情况下,我使用了前面提到的 startupstockphotos中的照片,用作div中的背景:

<div id="backgroundcontainer">
</div>

The CSS sets the image to cover the width of the element, and sets the height of the element to the background image:

CSS将图像设置为覆盖元素的宽度,并将元素的高度设置为背景图像:

div#backgroundcontainer {background-image: url(macbook-background.jpg);background-image: image-set("macbook-background.jpg" 1x,"macbook-background-2x.jpg" 2x);background-size: contain;background-repeat: no-repeat;max-width: 750px;margin: 0 auto;padding-top: 53.4%;position: relative;
}

I’ll have more to say about using Retina background images with image-set in an upcoming article.

在接下来的文章中,我将对使用带有image-set Retina背景图像有更多的话要说。

放置玩家 (Placing The Player)

Even if they’re familiar with CSS 3D, most web developers don’t realise that 3D transforms can be applied to any element… even <iframe>`, meaning that YouTube videos and other sources are open to manipulation in three dimensions.

即使他们熟悉CSS 3D,大多数Web开发人员也没有意识到3D变换可以应用于任何元素…甚至<iframe> `,这意味着YouTube视频和其他资源可以在三个维度上进行操作。

Videos from YouTube aren’t automatically responsive, but I’ve previously addressed how to solve that problem, and will use the same solution here:

YouTube的视频不会自动响应 ,但是我之前已经解决了如何解决该问题 ,并将在此处使用相同的解决方案:

<div id="backgroundcontainer"><div id="ivideo"><iframe frameborder="0" src="https://youtube.com/embed/V7be0UEJDdo…"></iframe></div>
</div>

The embedded video will autoplay; the next step is to set it on the page.

嵌入的视频将自动播放; 下一步是在页面上进行设置。

The specific code used in this YouTube example will be addressed in a future article.

此YouTube示例中使用的特定代码将在以后的文章中介绍。

发光角度 (The Light Angle)

To set the position of the video correctly, several things need to happen. The first is that the outer <div> element needs the correct perspective values applied:

要正确设置视频的位置,需要做几件事。 首先是外部<div>元素需要应用正确的perspective值:

div#backgroundcontainer { perspective: 472px;perspective-origin: 103% 8%;
}

We’ll use the fact that this outer container has relative positioning to set the absolute position of the inner <div> containing the video:

我们将使用这个外部容器具有相对位置的事实来设置包含视频的内部<div>的绝对位置 :

#ivideo {position: absolute;top: 0;right: 2.1%;width: 41.6%;padding-bottom: 21%;
}

The combination of absolute positioning together with width and padding-bottom makes the video responsive, if it is combined with the following declaration:

如果结合以下声明,则将绝对定位与widthpadding-bottom结合在一起可以使视频具有响应能力:

#ivideo iframe {position: absolute;width: 100%;height: 100%;
}

The values I used to set the correct angle for this video were:

我用来为此视频设置正确角度的值是:

#ivideo {transform: rotateX(10deg) rotateY(-7deg) translateY(74%);
}

Finding these values is a combination of experience, experimentation and testing. I knew that the vanishing point set by the perspective-origin value corresponded to the top right of the background image: you can see the vertical edges of the Macbook screen narrowing towards that location. iframe starts off in the same approximate location due to the positioning of its surrounding <div>, so moving it down (using translateY was the first order of operations. Then, I had to rotate it in X and Y. This was helped by using a small trick in Chrome’s Element inspector: placing your cursor in a CSS value and using the up and down cursor keys will raise and lower the value by 1.

找到这些值是经验,实验和测试的结合。 我知道perspective-origin值设置的消失点对应于背景图像的右上角:您可以看到Macbook屏幕的垂直边缘朝该位置变窄。 iframe由于其周围的<div>位置而在相同的近似位置开始,因此将其向下移动(使用translateY是操作的第一顺序。然后,我不得不将其旋转为X和Y。这通过使用Chrome的“元素”检查器中的一个小技巧:将光标置于CSS值中,并使用上下光标键将值增加或减少1。

Of course, the changes you make here will only take effect in the browser, not in the code of your page. If you wanted the changes to be written permanently into the code, you could use Chrome Workspaces to do so.

当然,您在此处所做的更改只会在浏览器中生效,而不会在页面代码中生效。 如果您希望将更改永久写入代码中,则可以使用Chrome Workspaces进行更改。

Chrome Element inspect property value adjusted with up-down cursor keys
Chrome元素检查使用上下光标键调整的属性值

剪切并打印 (Cut & Print)

Using this live experimentation, I gained the correct values to move the video to the right place. However, you may find that the perspective isn’t perfect at every viewport size. To fix this, I introduced a @media query:

通过这次现场实验,我获得了将视频移到正确位置的正确值。 但是,您可能会发现透视图并非在每个视口尺寸上都是完美的。 为了解决这个问题,我引入了@media查询:

@media screen and (max-width: 600px) {div#container { perspective: 250px;}
}

I have plans for at least one other variation of this technique: if you enjoyed it, I hope you’ll come back for more. To be alerted for new updates and more web development news, I’d suggest following me on Twitter… or, if you’re old school, subscribing to this site’s RSS feed.

我已经计划了这项技术的至少另一种变体:如果您喜欢它,我希望您会再来获得更多。 要收到有关新更新和更多Web开发新闻的警报,建议您在Twitter上关注我 ……或者,如果您是老学校,请订阅该站点的RSS feed 。

翻译自: https://thenewcode.com/367/Create-Web-Page-Cinemagraphs-with-CSS-3D-Transforms

css3d转换

css3d转换_使用CSS 3D转换创建网页电影摄影相关推荐

  1. web前端基础 html5+css3(十二.2D转换,动画,3D转换)

    一.2D转换 1.2D转换之移动translate (1)transform:translate(x,y); transform:translate(100px,100px); (2)transfor ...

  2. css加号图标_纯CSS制作各种各样的网页图标(三角形、暂停按钮、下载箭头、加号等)...

    三角形 .box{ width: 0; height: 0; border-top: 50px solid transparent; border-bottom: 50px solid transpa ...

  3. CSS 3D转换和动画(animation)

    一.空间转换 3D 3D坐标系 3D 坐标系比2D 多了一个Z轴. X 轴 往右越大,是正值, 否则反之 Y 轴 往下越大,是正值,否则反之 Z轴 (指向我们)越大,是正值,否则反之 3D位移 完整写 ...

  4. CSS 3D转换和动画

    空间转换 3D 3D坐标系 3D 坐标系比2D 多了一个Z轴. 一定要记住3个坐标轴取值的正反: X 轴 往右越大,是正值, 否则反之 Y 轴 往下越大,是正值,否则反之 Z轴 (指向我们)越大,是正 ...

  5. html 3d转换动画,开源项目:CSS 3D转换和动画学习示例教程

    下面介绍的开源项目,是CSS在动画/3D变换方面的一些应用,非常酷的效果,全部由CSS3来实现. 在这里JavaScript仅作为动画控制来使用,JS并不控制UI界面的具体呈现,切换动画.3D效果仅需 ...

  6. pythoncsv格式清洗与转换_数据预处理-清洗转换

    当数据质量校验完成后,针对有问题的数据要进行的是数据清洗和转换,另外还包括对正常数据的转换.数据清洗的主要作用包括:纠正错误.删除重复项.统一规格.修正逻辑.转换构造和数据压缩. 1. 纠正错误 错误 ...

  7. java对字符串编码转换_处理字符串编码转换java类详解

    该字符串处理类包括将ISO-8859-1编码的字符串转换成GBK编码 .对输入的字符串进行一次编码转换,防止SQL注入和验证URL地址是否存在的方法. 字符串处理类(编码转化.SQL注入.URL) i ...

  8. et结波导口转换_波导同轴转换

    功分器(DC-65GHz) 适配RF Switch Ⅳ座射频探针 新产品 板端连接器/End launch 高频低损耗稳幅稳相同轴电缆 微带测试探针 适配RF Switch Ⅴ座射频探针 同轴负载 同 ...

  9. python123平台作业答案进制转换_各种进制转换详解-python

    (1)各个进制的符号:b:二进制:o:八进制:d:十进制:x:十六进制 在python中,bin(),oct(),hex()返回值均为字符串而且会带有0b,0o,0o前缀 (2)各个进制相互转换 a) ...

  10. css 蒙版_简单CSS蒙版:创建图像小插图

    css 蒙版 Vignetting is the technique of fading of an image at its edges, often seen in wedding photogr ...

最新文章

  1. postgresql导入mysql的备份_PostgreSQL数据备份、导入转
  2. html运行代码出现问号乱码_Java 0基础入门(初识Html)
  3. 【一周入门MySQL—5】
  4. python下载网页中的pdf文件_【Python】Python的urllib模块、urllib2模块批量进行网页下载文件...
  5. 页面缓存 ehcache(简单的)
  6. RIM发警告 部分黑莓手机存在安全漏洞
  7. php军事网站源码,军事网站的设计与实现(PHP+MYSQL)(含录像)
  8. fatal: unable to access ‘https://github.com/PanJiaChen/vue-element-admin.git/‘: OpenSSL SSL_read: Co
  9. MusicXML 3.0 (4) - 谱号
  10. javafx css_JavaFX技巧13:研究Modena CSS文件
  11. js笔记(二)数组、对象、this
  12. JAVA入门级教学之(super关键字)
  13. 用于he染色组织细胞核分割的两阶段U-Net算法
  14. android rom 裁剪,Android之调用系统照相机并裁剪
  15. 開源搜索引擎爬蟲_六大開源搜索引擎工具 | 學步園
  16. tcpdump如何判断丢包_亿级规模的高可用微服务系统,如何轻松设计?
  17. 数据库删除表中多列语法总结
  18. 小米删除了文件无网络无服务器,两部小米手机无网络快速互传文件
  19. 【离散数学】集合论 第三章 集合与关系(6) 二元关系的定义、表示和运算及性质
  20. R语言使用order函数降序排序向量数据、设置decreasing参数进行降序排序

热门文章

  1. python群发邮件 不进垃圾箱_邮件群发不进垃圾箱
  2. 搭建网站基本步骤(搭建一个网站的步骤)
  3. 【opencv】颜色空间总结
  4. Python爬取曾今的K歌
  5. 当今排队方式方法_当今改善您的设计产品组合的5种方法
  6. SQL - 数据查询语句之字符串拆分
  7. 单片机外围电路设计攻略
  8. 写代码实现功能并不重要,重要的是一种独到的思维和架构
  9. Ubuntu安装teamviewer12
  10. 2021全球生活成本排名揭晓:香港不是第一,最贵城市是它