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.pswp.cn/news/393335.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393335.shtml
英文地址,請注明出處:http://en.pswp.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相…