react動畫庫_React 2020動畫庫

react動畫庫

Animations are important in instances like page transitions, scroll events, entering and exiting components, and events that the user should be alerted to.

動畫在諸如頁面過渡,滾動事件,進入和退出組件以及應提醒用戶的事件之類的實例中很重要。

In this article, we’ll take a look at 5 React animation libraries that can be integrated with React for interactive and attractive web pages.

在本文中,我們將研究5個React動畫庫,這些庫可以與React集成在一起,以生成交互式且吸引人的網頁。

0.建立自己的動畫庫 (0. Building Your Own Animation Library)

Building your own animations or even just composing animations out of existing libraries is something you should definitely try for yourself. It doesn’t have to be a complete ‘component library project’. Whenever you build a component you think you or your team may want to use in the future, simply publish it to Bit.dev.

一定要自己嘗試制作自己的動畫,甚至只是從現有庫中合成動畫。 它不必是完整的“組件庫項目”。 每當您構建組件時,您認為您或您的團隊將來可能希望使用,只需將其發布到Bit.dev即可

Once a component gets published to Bit.dev, it gets automatically documented (if you’re using prop-types or TypeScript). In addition, you can add your own example code snippets that would get rendered for you, on the component page.

組件一旦發布到Bit.dev ,它就會被自動記錄(如果您使用的是prop-types或TypeScript)。 此外,您可以在組件頁面上添加自己的示例代碼片段,這些片段將為您呈現。

It’s quite simply a good way to gradually build your own shareable collection of reusable React components.

這是逐步構建自己的可重用React組件的共享集合的一種好方法。

Image for post
Example: exploring React components published on Bit.dev
示例:瀏覽發布在Bit.dev上的React組件

1.React過渡小組 (1. React Transition Group)

React Transition Group is a comprehensive animation library with 7.1k Github stars. It has four components that display transitions from one component state to another using a declarative API used for mounting and unmounting of components:

React Transition Group是一個擁有7.1k Github星星的綜合動畫庫。 它具有四個組件,這些組件使用用于安裝和卸載組件的聲明性API顯示從一個組件狀態到另一組件狀態的轉換:

1. Transition

1.過渡

2. CSSTransition

2. CSSTransition

3. SwitchTransition

3. SwitchTransition

4. TransitionGroup

4. TransitionGroup

Let’s see how transition components can be used to create the following type of transitions:

讓我們看看如何使用過渡組件創建以下類型的過渡:

? ‘entering’

?“進入”

? ‘entered’

?“進入”

? ‘exiting’

?“退出”

? ‘exited’

?“退出”

To use the react-transition-group, install it using npm or yarn:

要使用react-transition-group,請使用npm或yarn安裝它:

# npm

#npm

# yarn

#紗

Let’s import the ‘Transition’ component from the ‘react-transition-group’ in to the App.js file.

讓我們從“ react-transition-group”中將“ Transition”組件導入App.js文件。

Set the transition component using a timeout and allow the component to begin the “enter” stage by setting the transition to true. As the current component changes state from ‘entered’ to “entering” and back to “entered”, we will set the “.box-entered” and “.box-entering” CSS classes to create the appropriate changes.

使用超時設置過渡組件,并通過將過渡設置為true來允許該組件開始“進入”階段。 當當前組件的狀態從“已輸入”更改為“已輸入”,然后再回到“已輸入”時,我們將設置“ .box-entered”和“ .box-entering” CSS類以創建適當的更改。

Set the keyframes that set the properties like position and color during the smooth transition.

設置關鍵幀,這些關鍵幀將設置平滑過渡期間的位置和顏色等屬性。

2.React真棒揭示 (2. React Awesome Reveal)

This is a React component written in TypeScript, and it uses the Intersection Observer API to add reveal animations. The intersection API detects the element as it appears in the viewport. Internally, the animations are accelerated using Animation.css that uses the benefit of hardware acceleration.

這是一個用TypeScript編寫的React組件,它使用Intersection Observer API添加顯示動畫。 相交API檢測到視口中出現的元素。 在內部,使用Animation.css加速了動畫,該動畫利用了硬件加速的優勢。

Here is an example of the Slide component using React Awesome Reveal.

這是使用React Awesome Reveal的Slide組件的示例。

Add the dependency of React Awesome Reveal as follows:

添加React Awesome Reveal的依賴項,如下所示:

using npm

使用npm

using yarn

用紗

Let’s import the Slide component from “react-awesome-reveal”. This animated component slides your content during the mounting of components.

讓我們從“ react-awesome-reveal”中導入Slide組件。 這個動畫組件會在組件安裝期間滑動您的內容。

Use the Slide components with the content and allow it to slide in at once.

將“幻燈片”組件與內容一起使用,并使其一次滑入。

There are various other effects like cascade, damping, direction, and duration. It also allows you to chain multiple effects together.

還有其他各種效果,例如級聯,阻尼,方向和持續時間。 它還允許您將多個效果鏈接在一起。

This is a quick example of chaining effects:

這是鏈接效果的快速示例:

3. Motion API (3. Motion API)

Motion API provides a simple animation, gesture API as a FrameX library, and maintains SVG and HTML semantics. Your highly animated prototypes are portable to a production-ready environment. It allows,

Motion API提供了一個簡單的動畫,手勢API作為FrameX庫,并維護SVG和HTML語義。 您動畫效果極強的原型可移植到可用于生產環境中。 它允許

1) Animation: Animation is automatically done by using an animate prop.

1)動畫:動畫是通過使用動畫道具自動完成的。

2) Gestures: Gestures like hover, tag, pan, and drag are supported as the React event system is extended.

2)手勢:隨著React事件系統的擴展,支持諸如懸停,標記,平移和拖動之類的手勢。

3) Variants: Sub-tress is animated using a single animate prop. It also orchestrates these animations with options like “when” and “staggerChildren”.

3)變體:使用單個動畫道具對子樹進行動畫處理。 它還使用“ when”和“ staggerChildren”等選項來編排這些動畫。

4) Server-side Rendering: Server-side rendering is possible with flashes of restyled content.

4)服務器端渲染:可以通過重新樣式化的內容的閃爍來實現服務器端渲染。

5) Motion values: This is used to create reactive chains of motion values that get updated during animations.

5)運動值:用于創建在動畫過程中更新的運動值的React鏈。

6) Scroll-based Animations: Motion makes scroll-based or parallax animations easy.

6)基于滾動的動畫:Motion使基于滾動或視差的動畫變得容易。

Motion works with React 16.8 and later versions. Install framer-motion using npm.

Motion適用于React 16.8和更高版本。 使用npm安裝framer-motion。

The official site is filled with examples. Let’s try out “AnimateSharedLayout” which allows the animation of different components sharing layout ID. Though it is in beta, you will be able to install it with the following command:

官方站點上有很多示例。 讓我們嘗試一下“ AnimateSharedLayout”,它允許不同組件的動畫共享布局ID。 盡管它處于測試版,但是您可以使用以下命令進行安裝:

Lets first create the data that needs to be displayed.

首先創建需要顯示的數據。

Let’s animate the above data using motion and AnimatedSharedLayout from “framer-motion”.

讓我們使用來自“ framer-motion”的運動和AnimatedSharedLayout為上述數據設置動畫。

Along with the motion components, CSS plays an important role in animation. Check out the CSS file for this example.

CSS與運動組件一起在動畫中起著重要作用。 請查看此示例CSS文件。

Example of Animated Shared Layout
動畫共享版式示例

4.ReactTweenful: (4. React Tweenful:)

React Tweenful creates real-world animations for your pages. It uses SVG to perform animations for various shapes, colors, and sizes. React Tweenful includes features like:

React Tweenful為您的頁面創建真實世界的動畫。 它使用SVG來執行各種形狀,顏色和大小的動畫。 React Tweenful包括以下功能:

1. Looping: Works for a specific number or an infinite loop.

1.循環:適用于特定數字或無限循環。

2. Easing techniques: This is a classic animation that starts with a point to move naturally along a curve. It gives an option to predefined easing. Custom easing can also be performed with Bezier.

2.緩動技術:這是一種經典動畫,其起始點是沿曲線自然移動。 它提供了預定義寬松的選項。 自定義緩動也可以使用Bezier執行。

3. Delayed animations: It is possible to set a delay to start and end the animation. You can also add a delay to current animations and events. In addition, it allows a negative delay that can mimic CSS animations.

3.延遲的動畫:可以設置開始和結束動畫的延遲。 您還可以向當前動畫和事件添加延遲。 此外,它允許產生可以模擬CSS動畫的負延遲。

4. Events support: Provides event support to manage animations.

4.事件支持:提供事件支持以管理動畫。

5. Animations based on percent: Allows percentages for CSS animations.

5.基于百分比的動畫:允許CSS動畫的百分比。

6. A component called “Tweenful” is provided to animate the DOM. Using this component the DOM nodes are manipulated easily.

6.提供了一個名為“ Tweenful”的組件來為DOM制作動畫。 使用此組件,可以輕松操縱DOM節點。

8. Animating SVG: To animation SVG nodes a specific SVG component is provided.

8.動畫SVG:為動畫SVG節點提供了特定的SVG組件。

9. Observer component: Supports Mounting and unmounting animations while the component is loading and unloading, with the Observer component.

9. Observer組件:支持使用Observer組件在組件加載和卸載時安裝和卸載動畫。

10. Handling child transitions during animations like removal of list or change of page requires observers. The ObserverGroup component handles child transitions during animations.

10.處理動畫過程中的子過渡(例如刪除列表或更改頁面)需要觀察者。 ObserverGroup組件處理動畫期間的子過渡。

Now let’s look at an example of React Tweenful. Start by installing it using npm:

現在讓我們看一下React Tweenful的示例。 首先使用npm安裝它:

Then let’s download the zip folder for the repo and then navigate to src folder to get the required library file (In this example, we’re using Observer.js)

然后讓我們下載的zip文件夾的回購 ,然后導航到src文件夾,以獲得所需要的庫文件(在這個例子中,我們使用Observer.js)

Let’s import it as follows:

讓我們如下導入它:

Add the following props object to configure the animation.

添加以下props對象以配置動畫。

Now let’s write our class.

現在讓我們編寫我們的課程。

This is where we add the object to be animated. The Observer and Tweentiful.div components will be placed inside the return statement of our App class:

這是我們要添加動畫對象的地方。 Observer和Tweentiful.div組件將放置在我們的App類的return語句內:

That’s it. This is the result:

而已。 結果如下:

5. React運動 (5. React Motion)

This is a popular library for React. The animations created look natural and use physics concepts to provide a realistic feel.

這是React的流行庫。 所創建的動畫看起來自然,并使用物理概念提供逼真的感覺。

The demo provides various examples with varying levels of complexity. The community has provided a large set of live examples and demos of games, animations, transitions, and drawings along with many Youtube channels and tutorials.

該演示提供了具有不同復雜程度的各種示例。 該社區提供了大量的游戲,動畫,過渡和繪圖的實時示例和演示,以及許多Youtube頻道和教程。

This library is an alternative to the react transition group. The API avoids using hard-coded values and durations to create animations. Hard-coding the values does not lead to smooth transitions when interrupted. To create realistic animations, React Motion uses the values of stiffness, damping, and precision during the animations. The effects are created using the below API.

該庫是React過渡組的替代方法。 API避免使用硬編碼的值和持續時間來創建動畫。 硬編碼值在中斷時不會導致平滑過渡。 為了創建逼真的動畫,React Motion在動畫過程中使用剛度,阻尼和精度值。 使用以下API創建效果。

1) Spring: Spring is a function and defines the animation of destination value by setting stiffness and damping to the given value. Check the demo on how the values of stiffness and damping affect spring motion.

1) Spring :Spring是一個函數,它通過將剛度和阻尼設置為給定值來定義目標值的動畫。 查看演示中有關剛度和阻尼值如何影響彈簧運動的演示。

2) Motion: To wrap any component wrap it around the motion and set up the props like spring functions and inline styling to animate it.

2)動作:要包裹任何組件,請將其包裹在動作周圍,并設置諸如彈簧功能和內嵌樣式的道具以對其進行動畫處理。

3) Staggered Motion: This component sets the interpolated value of an item depending on the value of previous items. This motion is used for menu animation where the links stagger, but the position is dependent on the previous menu links.

3)交錯運動:此組件根據先前項目的值設置項目的插值。 此動作用于菜單動畫,其中鏈接交錯,但位置取決于先前的菜單鏈接。

4) Transition Motion: Used during mounting and unmounting of items. For example, if you have three items and you would like to animate the third item while the component renders, you can use the TransitonMotion component by defining the key, data and style required for the animation.

4)過渡運動:在物品的裝卸過程中使用。 例如,如果您有三個項目,并且想在組件渲染時為第三個項目設置動畫,則可以通過定義動畫所需的關鍵點,數據和樣式來使用TransitonMotion組件。

Let’s look at an example using React Motion. We start by installing it via npm:

讓我們來看一個使用React Motion的示例。 我們首先通過npm安裝它:

We’ll be creating a ball that rolls away when we click on it. Import React Motion to your App.js file.

我們將創建一個單擊時會滾開的球。 將React Motion導入您的App.js文件。

Now let’s write the css for our animation.

現在,讓我們為動畫編寫CSS。

Add the following functions to handle what happens when we click on the ball:

添加以下函數來處理我們單擊球時發生的情況:

This is the Motion component. It defines the object to be animated, in this case, it is the image of the ball.

這是運動組件。 它定義了要動畫的對象,在這種情況下,它是球的圖像。

This is how the result will look:

結果如下所示:

結論 (Conclusion)

We looked at five libraries for creating animations and transitions for your websites. Each of these offers a unique way of creating animations. Now all libraries work well with all scenarios and requirements. So it is important that you experiment with at least a few of them before selecting one.

我們研究了五個用于為您的網站創建動畫和過渡的庫。 每一種都提供了一種獨特的動畫制作方式。 現在,所有庫都能很好地滿足所有方案和要求。 因此,在選擇一個之前,至少要對其中一些進行試驗,這一點很重要。

學到更多 (Learn More)

翻譯自: https://blog.bitsrc.io/react-animation-libraries-for-2020-437a21c73fed

react動畫庫

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274392.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274392.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274392.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Weather

public class WeatherModel { #region 定義成員變量 private string _temperature ""; private string _weather ""; private string _wind ""; private string _city ""; private …

線框模型_進行計劃之前:線框和模型

線框模型Before we start developing something, we need a plan about what we’re doing and what is the expected result from the project. Same as developing a website, we need to create a mockup before we start developing (coding) because it will cost so much…

撰寫論文時word使用技巧(轉)

------------------------------------- 1. Word2007 的表格自定義格式額度功能是很實用的,比如論文中需要經常插入表格的話, 可以在“表格設計”那里“修改表格樣式”一次性把默認的表格樣式設置為三線表,這樣, 你以后每次插入的…

工作經驗教訓_在設計工作五年后獲得的經驗教訓

工作經驗教訓This June it has been five years since I graduated from college. Since then I’ve been working as a UX designer for a lot of different companies, including a start-up, an application developer, and two consultancy firms.我從大學畢業已經五年了&a…

Wayland 源碼解析之代碼結構

來源:http://blog.csdn.net/basilc/article/details/8074895 獲取、編譯 Wayland 及其依賴庫可參考 Wayland 官方網站的 Build 指南:http://wayland.freedesktop.org/building.html。 Wayland 實現的代碼組成可以分成以下四部分: 1. Wayland…

中文排版規則_非設計師的5條排版規則

中文排版規則01僅以一種字體開始 (01 Start with only one font) The first tip for non-designers dealing with typography is simple and will make your life much easier: Stop combining different fonts you like individually and try using only one font in your fut…

基本響應性的Web設計測試工具

在重新設計頁面的過程中。要使頁面完全響應的設計(這意味著它會重新調整大小根據瀏覽器的尺寸和方向)。如iPhone和iPad的移動電話和平板電腦我碰到了一些非常方便的響應設計工具,幫我測試網站在不同的屏幕響應。下面的這些響應的網頁設計工具…

ux設計_聲音建議:設計UX聲音的快速指南

ux設計Mating calls, warning grunts, and supportive coos are some of the sounds heard throughout the animal kingdom. All species use finely-tuned noises to communicate to one another and inform others of an action or behavior. We humans aren’t all that dif…

css3高級和低級樣式屬性先后順序

寫css hack 時,由于hack主要針對的是個別瀏覽器,hack的書寫順序應當是從一般到特殊的寫法。 如: .box { width:200px; height:200px; position:fixed; left:0; top:0; _position:absolute; } 如果顛倒順序,從特殊到一般&#xff0…

sans serif_Sans和Serif相遇可愛

sans serifI first noticed it in this tweet. Exciting upcoming product and snazzy motion work aside, “What a fascinating logotype!”, I exclaimed!我在此推文中首先注意到了它。 我驚呼即將推出的激動人心的產品和令人眼花,亂的動作,“多么迷人…

[ckeditor系列]ckeditor 自己寫的一個簡單的image上傳js 運用iframe的ajax上傳

ckeditor最近修改一個上傳的,原來的Image的上傳插件功能很多,但是自己用,沒有必要,就進行了修改,后來就改成了目前的樣子,根據_samples/api_dialog.html 進行了修改,把頁面里面的調用都進行了修…

sql 避免除0錯誤_設計簡歷時避免這3個常見的UX錯誤

sql 避免除0錯誤重點 (Top highlight)Having a great looking resume on hand is very important when you’re looking for a job. It is your ticket to land the interview that will get you one step closer to that one job you’ve been dreaming of.在找工作時&#xf…

一個網站自動化測試程序的設計與實現

CSDN博客不再經常更新,更多優質文章請來 粉絲聯盟網 FansUnion.cn! (FansUnion) 代碼 下載地址:http://download.csdn.net/detail/fansunion/5018357(免積分) 代碼亮點:可讀性很好,注釋詳盡 背景 工作中,在維護一…

如何編寫數據庫可視化界面_編寫用于數據可視化的替代文本

如何編寫數據庫可視化界面什么是替代文字 (What is Alt Text) Alt text (sometimes called Alt tags or alternative text) are written descriptions added to images that convey the meaning of the visual. Good alt text helps more people understand the content. Assis…

(轉)swc與swf的區別

在Flash Builder中用Actionscript寫的類可以打包成swc或swf, 在Flash CS中制作的元件也可以打包成swc或swf文件, 一個swc或swf文件中可以包含多個類或元件, 每個元件會映射成一個類, 因此,在Flash Builder中的類和在Fl…

js 驗證各種格式類型的正則表達式

<script src"scripts/jquery-1.4.1.js" type"text/javascript"></script> <script language"javascript" type"text/javascript"> /** * 定義驗證各種格式類型的正則表達式對象 */ var Regexs { email: …

reloaddata 跳動_紙跳動像素

reloaddata 跳動I would like to open with a problem.我想開一個問題。 Why are so many designer going straight to pixels?為什么這么多設計師直接使用像素&#xff1f; Over the past few years i’ve witnessed this in my team, my clients and others throughout th…

使用自定義RadioButton和ViewPager實現TabHost效果和帶滑動的頁卡效果。

參考自http://www.apkbus.com/android-86125-1-1.html 這篇文章技術含量一般&#xff0c;大家別見笑。源碼我以測試&#xff0c;在底部可下載。 好了先上效果圖&#xff1a; 以下是實現步驟&#xff1a; 1、準備自定義RadioButton控件的樣式圖片等&#xff0c;就是準…

利益相關者軟件工程_改善開發人員團隊與非技術利益相關者之間交流的方法

利益相關者軟件工程Whether you’re working on a startup or a big company, keeping your stakeholders and non-technical partners engaged and up to date on what the tech team has been building can be hard.無論您是在初創公司還是大公司中工作&#xff0c;都要讓您的…

Hibernate的檢索策略

Hibernate的Session在加載一個Java對象時&#xff0c;可以將與這個對象相關聯的其他Java對象都加載到緩存中&#xff0c;以便程序及時調用。但有些情況下&#xff0c;我們不需要加載太多無用的對象到緩存中&#xff0c;一來這樣會撐爆內存&#xff0c;二來增加了訪問數據庫的次…