web动画_Web动画简介

web动画

by CodeDraken

由CodeDraken

Web动画简介 (An Introduction to Web Animations)

In this introduction to web animations article, we will cover basic CSS animations using pseudo-classes, transitions, and transformations.

在此Web动画简介中,我们将介绍使用伪类过渡转换的基本CSS动画。

If you’re unsure why you should use CSS animations then take a look at these articles.

如果不确定为什么要使用CSS动画,请阅读这些 文章 。

Some basic ( and very ugly (for now) ) example code for this article will be on CodePen:

本文的一些基本(现在非常难看)示例代码将在CodePen上发布:

已触发 (Triggered)

Before we jump into some animations, let’s think about how they’re going to be activated. Most of our animations won’t run immediately when a page loads. More commonly they’ll be triggered by a class change (via JavaScript) or using Pseudo Classes.

在进入一些动画之前,让我们考虑一下如何激活它们。 页面加载后,我们大多数动画不会立即运行。 通常, 它们是由类更改(通过JavaScript)或使用伪类触发的。

伪F (Pseudo Foo)

Here are a few pseudo-classes that are most commonly used for animations.

以下是一些最常用于动画的伪类 。

:hoverThe hover pseudo-class is triggered when you hover over the target with the mouse. In this example, we set the <;p> to change its color to blue when hovered. It will revert back to its original color after the mouse moves off of it.

:hover当您将鼠标悬停在目标上时 ,将触发悬停伪类。 在此示例中,我们将< ; p>设置为在悬停时将其颜色更改为蓝色。 鼠标移开后,它将恢复为原始颜色。

<style> #hover-example:hover {  color: blue;  cursor: pointer; }</style>
<p id=”hover-example”>Hover example</p>

:focus

:焦点

“The :focus CSS pseudo-class represents an element (such as a form input) that has received focus.” — MDN
“:focus CSS伪类表示已获得焦点的元素(例如表单输入)。” — MDN

(um… isn’t that like using a word to define itself??)

(嗯……这不像用一个词来定义自己吗?)

Focus is mainly used for inputs and buttons when they’re selected/activated — that is, when you click on an input or tab into it. In this example, clicking or tabbing into the input will cause it to change the width and its background color. Clicking out of it will cause it to revert back to its original size (and color).

焦点主要用于选择/激活输入和按钮时, 即单击输入或选项卡时 。 在此示例中,单击或制表符输入将导致其更改宽度和其背景颜色。 单击它会使其恢复为原始大小(和颜色)。

<style> input:focus {  background-color: #f4f4f4;  width: 50vw; }</style>
<input type=”text”>

:activeActive seems similar to focus, but it’s usually only triggered for a split second. The first use case that comes to mind are anchors (links). In this example, we make anything with the class activate change while it’s being clicked (that is, while it’s active).

:active Active看起来类似于焦点,但是通常仅在瞬间触发 。 我想到的第一个用例是锚点(链接)。 在此示例中,我们通过单击类(即,在其处于活动状态时) activate更改来进行任何操作。

<style> .activate:active {  background-color: orange; }</style>
<p class=”activate”>Click me!</p><div class=”activate”>Activate me!</div><button class=”activate”>Hold me!</button>

变形金刚 (Transformers)

“The transform CSS property lets you rotate, scale, skew or translate a given element. “ — MDN
“ transform CSS属性使您可以旋转,缩放,倾斜或平移给定元素。 “-MDN

Transform is where you take your CSS animations to the next level. There are 21 or so functions you can use with transform, but we will not cover all of them in this article.

变换是将CSS动画提升到新水平的地方。 您可以在transform中使用大约21个函数,但是本文将不介绍所有这些函数。

翻译(x,y) (Translate ( x, y ))

To translate means you’re moving something. In the example below, we move whatever has the translate class 10rem over on the X-axis and 5rem over on the Y-axis. (If you’re not familiar with rem, you can use pixels, too.)

翻译意味着您正在移动某些东西。 在下面的例子中,我们移动任何有translate10rem了在X轴和5rem了在Y轴。 (如果您不熟悉rem,也可以使用像素。)

This is the shorthand function that combines X and Y, but you can use translateX or translateY instead if you prefer.

这是组合X和Y的简写函数,但是如果您愿意,可以改用translateXtranslateY

<style> .translate {  transform: translate(10rem, 5rem) }</style>

比例尺(x,y) (Scale ( x, y ))

Similar to translate, scale also has a scaleX, scaleY, and a scale shorthand function. Use scale to change the size of something. In the example below, elements with the scale class are reduced to half their size.

translate相似,scale也具有scaleXscaleYscale简写函数。 使用比例改变某物的大小 。 在下面的示例中,具有scale类的元素的大小减小到一半。

<style> .scale {  transform: scale(0.5); }</style>

变换原点 (x,y,z) (Transform-origin ( x, y, z ))

Transform-origin is an important property when dealing with animations, especially rotations. It’s a bit odd and difficult to explain with just words, and I strongly suggest looking at the MDN docs for this one if you’re not already familiar with changing origins (like in Photoshop). The documentation words it best:

处理动画,尤其是旋转时,变换原点是重要的属性。 仅凭文字很难解释,这有点奇怪而且很难解释,如果您还不熟悉更改来源(例如在Photoshop中),强烈建议您查看MDN文档。 该文档最好说:

“The transformation origin is the point around which a transformation is applied” — MDN
“转换起点是应用转换的起点” — MDN

Imagine a wheel:

想象一个轮子:

When the wheel spins it rotates around that center point. But now imagine that center point was moved to, say, the top left corner. Now the wheel rotates around that new point thus providing a very different experience. That center point is similar to the origin. See the CodePen for an interactive example.

车轮旋转时,它将绕该中心点旋转。 但是现在想象一下,中心点已移至左上角。 现在,车轮围绕该新点旋转,从而提供了非常不同的体验。 该中心点与原点相似。 有关交互式示例,请参见CodePen 。

旋转(角度) (Rotate (angle))

Rotate does exactly what it says it does. You can specify any angle, negative, positive, any number and it will spin it around that much. There are a few different values you can use (deg, rad, grad) — see more value types on MDN.

Rotate完全按照它说的去做。 您可以指定任意角度,可以为负,为正,可以为任意角度,并且可以绕任意角度旋转。 您可以使用一些不同的值(度,弧度,梯度), 请参阅MDN上的更多值类型 。

使事情顺利 (Making things smooth)

Using transitions we can smooth things out and control the flow of our animations.

使用过渡,我们可以使事情变得平滑并控制动画的流向。

Transitions are like tweens or a speed control for our animation. It can take 4 arguments, and I’ll cover each in detail.

过渡就像补间动画或动画的速度控制一样。 它可能需要4个参数,我将详细介绍每个参数。

过渡财产 (transition-property)

Transition property is what you’re animating. This could be color, size, a transform, and so on. You could also say all to transition everything, but you should avoid doing this and be more specific.

过渡属性就是您要设置的动画 。 这可以是颜色,大小,变换等。 您也可以说all以过渡所有内容,但应避免这样做,并且要更加具体。

There’s a huge list of properties you can animate on MDN. You should avoid animating anything not on the list.

您可以在MDN上设置动画的属性列表很多 。 您应该避免对列表中没有的内容进行动画处理。

transition-property: all;

transition-property: all;

过渡持续时间 (transition-duration)

This is how long the animation will take to finish. Use seconds or milliseconds.

这是动画完成所需的时间 。 使用秒或毫秒。

transition-duration: 2s;

transition-duration: 2s;

过渡计时功能 (transition-timing-function)

This is where it gets more complex. The transition timing function is an acceleration curve that describes how the animation flows. Take a look at these sites to see what this curve looks like and how it affects the animation.

这就是它变得更加复杂的地方。 过渡时间函数是描述动画如何流动加速曲线 。 查看这些 站点,以查看该曲线的外观以及它如何影响动画。

You can have it ease in then ease out, slowly start then finish fast, or a more complex flow with some slow parts and fast parts. There are many ways to have your animation flow.

您可以轻松地进行然后轻松地进行,缓慢地开始然后快速完成,或者使用一些较慢的部分和较快的部分进行更复杂的处理。 有多种方法可以使动画流动。

Luckily, there are some predefined values we can use:

幸运的是,我们可以使用一些预定义的值:

easeease-inease-outease-in-outlinearstep-startstep-end

You’ll have to play with them a bit to find the one for your animation.

您必须与他们一起玩一些才能找到适合您的动画的那个。

Sometimes we’ll have to make our own using cubic-bezier (or use a library). For that, I suggest you find an online tool (see above links) or use your browser’s developer tools to make one.

有时,我们必须使用cubic-bezier (或使用库 )来制作自己的。 为此,我建议您找到一种在线工具(请参阅上面的链接),或使用浏览器的开发人员工具进行构建。

transition-timing-function: cubic-bezier(.29, 1.01, 1, -0.68);

transition-timing-function: cubic-bezier(.29, 1.01, 1, -0.68);

过渡延迟 (transition-delay)

This is perhaps the simplest value. Transition-delay is the time it will wait before starting the effect. Use seconds or milliseconds.

这也许是最简单的值。 Transition-delay是开始效果之前等待的时间。 使用秒或毫秒。

transition-delay: 500ms;

transition-delay: 500ms;

过渡 (属性,持续时间,时间,延迟) (Transition (property, duration, timing, delay))

You’ve guessed it, this is the shorthand to combine all of the above functions.

您已经猜到了,这是结合以上所有功能的简写

Here is what it looks like with one transition:

这是一个过渡的样子:

transition: background 1s ease-in-out 0.5s;

transition: background 1s ease-in-out 0.5s;

For multiple, you need to add them to the same transition separated by commas.

对于多个,您需要将它们添加到由逗号分隔的相同过渡中。

transition: background 1s ease-in-out 0.5s,width 2s ease-in,height 1.5s;

结论 (In conclusion)

This is all you need to start making interactive websites. Go practice what you’ve learned, and once you have mastered the topics covered here, you can move on to more advanced animations.

这就是开始制作交互式网站所需的一切。 练习所学知识,掌握了此处介绍的主题之后,就可以继续学习更高级的动画。

In the next article (or two) I’ll talk about keyframes, 3D transforms, performance, JavaScript animations, and more.

在下一篇(或两篇)文章中,我将讨论关键帧,3D变换,性能,JavaScript动画等。

Thanks for reading! If you have any questions, comments, or criticism, then please leave a comment below and I’ll respond ASAP.

谢谢阅读! 如果您有任何疑问,意见或批评,请在下面留言,我将尽快答复。

翻译自: https://www.freecodecamp.org/news/an-introduction-to-web-animations-86f45de2a871/

web动画

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

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

相关文章

java统计空间占用_JVM —— Java 对象占用空间大小计算

引用类型(reference type&#xff1a; Integer)在 32 位系统上每一个占用 4bytes(即32bit&#xff0c; 才干管理 2^324G 的内存), 在 64 位系统上每一个占用 8bytes(开启压缩为 4 bytes)。四. 对齐填充HotSpot 的对齐方式为 8 字节对齐。不足的须要 Padding 填充对齐&#xff0…

源于十年来的点滴积累——《变革中的思索》印行出版

源于归国十年来的点滴积累, 集结成书的《变革中的思索》&#xff0c;日前由电子工业出版社刊印出版。 这本书共有五个章节&#xff0c;分别是解码创新、中国智造、管理心得、我和微软、心灵记忆——前三章偏重技术&#xff0c;更多理性的思考; 后两章则工作生活中的所见所闻&am…

SpringBoot声明式事务

目录 事务的基本特征隔离级别传播行为Transcation事务的基本特征&#xff08;ACID&#xff09; Atomic&#xff08;原子性&#xff09; 事务中包含的操作被看作一个整体的业务单元&#xff0c;这个业务单元中的操作要么全部成功&#xff0c;要么全部失败&#xff0c;不会出现部…

leetcode1437. 是否所有 1 都至少相隔 k 个元素

给你一个由若干 0 和 1 组成的数组 nums 以及整数 k。如果所有 1 都至少相隔 k 个元素&#xff0c;则返回 True &#xff1b;否则&#xff0c;返回 False 。 示例 1&#xff1a; 输入&#xff1a;nums [1,0,0,0,1,0,0,1], k 2 输出&#xff1a;true 解释&#xff1a;每个 1 …

数据结构教程网盘链接_数据结构101:链接列表

数据结构教程网盘链接by Kevin Turney凯文特尼(Kevin Turney) Like stacks and queues, Linked Lists are a form of a sequential collection. It does not have to be in order. A Linked list is made up of independent nodes that may contain any type of data. Each no…

多线程之间的通信(等待唤醒机制、Lock 及其它线程的方法)

一、多线程之间的通信。 就是多个线程在操作同一份数据&#xff0c; 但是操作的方法不同。     如&#xff1a; 对于同一个存储块&#xff0c;其中有两个存储位&#xff1a;name sex&#xff0c; 现有两个线程&#xff0c;一个向其中存放数据&#xff0c;一个打印其中的数…

Linux iptables 配置详解

一、配置一个filter表的防火墙 1. 查看本机关于 iptables 的设置情况 # iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) …

06 Nginx

1.检查linux上是否通过yum安装了nginx rpm -qi nginx2.解决安装nginx所依赖包 yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel ope…

java编写安卓程序代码,安卓:从Android的Java源代码code创建UML

i am looking for a program that can create automatically an Uml from my Java-Android source code.I have tested ArgoUml, but it does not support Android.Have any one a suggestion?Thanks!解决方案I can second what Tom Morris wrote in the comment above. Even …

leetcode1052. 爱生气的书店老板(滑动窗口)

今天&#xff0c;书店老板有一家店打算试营业 customers.length 分钟。每分钟都有一些顾客&#xff08;customers[i]&#xff09;会进入书店&#xff0c;所有这些顾客都会在那一分钟结束后离开。 在某些时候&#xff0c;书店老板会生气。 如果书店老板在第 i 分钟生气&#xf…

amazon alexa_在Amazon Alexa上推出freeCodeCamp编码琐事测验

amazon alexaNow you can learn coding concepts hands-free using an Amazon Echo.现在&#xff0c;您可以使用Amazon Echo免提学习编码概念。 freeCodeCamp.org contributor David Jolliffe created a quiz game with questions on JavaScript, CSS, networking, and comput…

第一类第二类丢失更新

第一类丢失更新 A事务撤销时&#xff0c;把已经提交的B事务的更新数据覆盖了。这种错误可能造成很严重的问题&#xff0c;通过下面的账户取款转账就可以看出来&#xff1a; 时间 取款事务A 转账事务B T1 开始事务 T2 开始事务 T3 查询账户余额为1000元 …

oracle数据字典表与视图

oracle数据字典表与视图 数据字典是数据的数据&#xff0c;也就是元数据。描述了数据库的物理与逻辑存储与相应的信息。模式中对象的定义信息&#xff0c;安全信息&#xff0c;完整性约束信息&#xff0c;和部分的性能监控信息等。数据字典表 与视图存储在system表空间中的。有…

团队作业——项目Alpha版本发布

---恢复内容开始--- https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/homework/3329 <作业要求的链接> Gorious Computer <写上团队名称> 发布项目α版本&#xff0c;对项目…

java脏字过滤_脏字过滤

1.[文件]SensitiveWordFilter.java ~ 7KB下载(141)package com.forgov.sharpc.infrastruture.util;import static java.util.Collections.sort;import java.util.ArrayList;import java.util.Collection;import java.util.Comparator;import java.util.HashSet;import java.uti…

react中使用构建缓存_完整的React课程:如何使用React构建聊天室应用

react中使用构建缓存In this video course, youll learn React by building a chat room app.在本视频课程中&#xff0c;您将通过构建聊天室应用程序来学习React。 By the end of the video, youll have a solid understanding of React.js and have your very own chat room…

leetcode1509. 三次操作后最大值与最小值的最小差

给你一个数组 nums &#xff0c;每次操作你可以选择 nums 中的任意一个元素并将它改成任意值。 请你返回三次操作后&#xff0c; nums 中最大值与最小值的差的最小值。 示例 1&#xff1a; 输入&#xff1a;nums [5,3,2,4] 输出&#xff1a;0 解释&#xff1a;将数组 [5,3,…

MySQL异步复制

准备&#xff1a;主备库版本一致&#xff0c;正常安装软件。 1、主库上设置一个复制使用的账户&#xff1a; mysql> grant replication slave on *.* to rep1192.168.100.136 identified by dbking; Query OK, 0 rows affected (0.18 sec) mysql> select user,host,passw…

开源一个爬取redmine数据的测试报告系统

背景 软件测试的最后有一道比较繁琐的工作&#xff0c;就是编写测试报告。手写测试报告在数据统计和分析上面要耗费比较大的事件和精力。之前工作室使用mantis管理bug缺陷。公司有内部有个系统&#xff0c;可以直接从mantis上面获取数据并进行统计&#xff0c;生成一份测试报告…

java cxf 双向通讯_CXF 在spring boot 2 发布多个服务

0. 问题来源之前配置cxf服务端都是在spring 3以下&#xff0c;后来使用spring mvc 还都是基于xml的配置文件模式&#xff0c;在springboot模式下&#xff0c;实现起来更为简单了。此次记录下spring boot 2下的实现方式。1. 准备工作项目中&#xff0c;直接拉入spring boot cxf相…