-
-
Notifications
You must be signed in to change notification settings - Fork 154
Create CSS-Animations.md #750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| --- | ||
| id: css-animations | ||
| title: CSS Animations | ||
| sidebar_label: CSS Animations | ||
| tags: [html, introduction, web development, markup language, hyper text, web pages, career opportunities, personal growth, web-development, web design, web pages, websites, career opportunities, contribute to the web, stay relevant, express yourself, learn other technologies, have fun, how to use html, steps to start using html, set up your development environment, create your first html document, learn html syntax and structure, explore html elements and-attributes] | ||
| description: In this tutorial you will learn about animations in CSS | ||
| --- | ||
|
|
||
| ## What are CSS Animations? | ||
| An animation lets an element gradually change from one style to another. | ||
| You can change as many CSS properties you want, as many times as you want. | ||
| To use CSS animation, you must first specify some keyframes for the animation. | ||
|
|
||
| Keyframes hold what styles the element will have at certain times. | ||
|
|
||
| ## The `@keyframes` Rule | ||
| When you specify CSS styles inside the `@keyframes` rule, the animation will gradually change from the current style to the new style at certain times. | ||
| To get an animation to work, you must bind the animation to an element. | ||
|
|
||
| ```css | ||
| /* The animation code */ | ||
| @keyframes example { | ||
| from {background-color: red;} | ||
| to {background-color: yellow;} | ||
| } | ||
|
|
||
| /* The element to apply the animation to */ | ||
| div { | ||
| width: 100px; | ||
| height: 100px; | ||
| background-color: red; | ||
| animation-name: example; | ||
| animation-duration: 4s; | ||
| } | ||
| ``` | ||
| <BrowserWindow url="http://127.0.0.1:5500/index.html"> | ||
ajay-dhangar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div style={{ | ||
| width: '100px', | ||
| height: '100px', | ||
| backgroundColor: 'red', | ||
| animation: 'myAnimation 4s infinite', | ||
| padding: '5px', | ||
| }}> | ||
| Hello World! | ||
| </div> | ||
| <style>{` | ||
| @keyframes myAnimation { | ||
| from { background-color: red; } | ||
| to { background-color: yellow; } | ||
| } | ||
| `}</style> | ||
| </BrowserWindow> | ||
|
|
||
| The `animation-duration` property defines how long an animation should take to complete. If the `animation-duration` property is not specified, no animation will occur, because the default value is 0s (0 seconds). | ||
| In the example above we have specified when the style will change by using the keywords "from" and "to" (which represents `0%` (start) and `100%` (complete)). | ||
| It is also possible to use percent. By using percent, you can add as many style changes as you like. | ||
|
|
||
| ## Delay an Animation | ||
| The `animation-delay` property specifies a delay for the start of an animation. | ||
|
|
||
| ```css | ||
| div { | ||
| width: 100px; | ||
| height: 100px; | ||
| position: relative; | ||
| background-color: red; | ||
| animation-name: example; | ||
| animation-duration: 4s; | ||
| animation-delay: 2s; | ||
| } | ||
| ``` | ||
| <BrowserWindow minHeight={400} url="http://127.0.0.1:5500/index.html"> | ||
| <div className="Delay-an-Animation" style={{ | ||
| width: '100px', | ||
| height: '100px', | ||
| position: 'relative', | ||
| backgroundColor: 'red', | ||
| animationName: 'DelayAnAnimationExample', | ||
| animationDuration: '4s', | ||
| animationDelay: '2s', | ||
| padding: '5px', | ||
| }}> | ||
| Hello World! | ||
| </div> | ||
| <style>{` | ||
| @keyframes DelayAnAnimationExample { | ||
| 0% { background-color: red; left: 0px; top: 0px; } | ||
| 25% { background-color: yellow; left: 200px; top: 0px; } | ||
| 50% { background-color: blue; left: 200px; top: 200px; } | ||
| 75% { background-color: green; left: 0px; top: 200px; } | ||
| 100% { background-color: red; left: 0px; top: 0px; } | ||
| } | ||
| .Delay-an-Animation { | ||
| position: absolute; | ||
| } | ||
| `}</style> | ||
| </BrowserWindow> | ||
|
|
||
| # Times animation should run | ||
| The `animation-iteration-count` property specifies the number of times an animation should run. | ||
|
|
||
| ```css | ||
| div { | ||
| width: 100px; | ||
| height: 100px; | ||
| position: relative; | ||
| background-color: red; | ||
| animation-name: example; | ||
| animation-duration: 4s; | ||
| animation-iteration-count: 3; | ||
| } | ||
| ``` | ||
|
|
||
ajay-dhangar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <BrowserWindow minHeight={400} url="http://127.0.0.1:5500/index.html"> | ||
| <div style={{ | ||
| width: '100px', | ||
| height: '100px', | ||
| position: 'relative', | ||
| backgroundColor: 'red', | ||
| animationName: 'example', | ||
| animationDuration: '4s', | ||
| animationIterationCount: 3, | ||
| padding: '5px', | ||
| }}> | ||
| Hello World! | ||
| </div> | ||
| <style>{` | ||
| @keyframes example { | ||
| 0% { background-color: red; left: 0px; top: 0px; } | ||
| 25% { background-color: yellow; left: 200px; top: 0px; } | ||
| 50% { background-color: blue; left: 200px; top: 200px; } | ||
| 75% { background-color: green; left: 0px; top: 200px; } | ||
| 100% { background-color: red; left: 0px; top: 0px; } | ||
| } | ||
| `}</style> | ||
| </BrowserWindow> | ||
|
|
||
| # Direction of the animation | ||
|
|
||
| The `animation-direction` property specifies whether an animation should be played forwards, backwards or in alternate cycles. | ||
|
|
||
| The `animation-direction` property can have the following values: | ||
|
|
||
| - `normal` - The animation is played as normal (forwards). This is default | ||
| - `reverse` - The animation is played in reverse direction (backwards) | ||
| - `alternate` - The animation is played forwards first, then backwards | ||
| - `alternate-reverse` - The animation is played backwards first, then forwards | ||
|
|
||
| ```css | ||
| div { | ||
| width: 100px; | ||
| height: 100px; | ||
| position: relative; | ||
| background-color: red; | ||
| animation-name: example; | ||
| animation-duration: 4s; | ||
| animation-direction: reverse; | ||
| } | ||
| ``` | ||
| <BrowserWindow minHeight={400} url="http://127.0.0.1:5500/index.html"> | ||
| <div style={{ | ||
| width: '100px', | ||
| height: '100px', | ||
| position: 'relative', | ||
| backgroundColor: 'red', | ||
| animationName: 'example', | ||
| animationDuration: '4s', | ||
| animationDirection: 'reverse', | ||
| padding: '5px', | ||
| }}> | ||
| Hello World! | ||
| </div> | ||
| <style>{` | ||
| @keyframes example { | ||
| 0% { background-color: red; left: 0px; top: 0px; } | ||
| 25% { background-color: yellow; left: 200px; top: 0px; } | ||
| 50% { background-color: blue; left: 200px; top: 200px; } | ||
| 75% { background-color: green; left: 0px; top: 200px; } | ||
| 100% { background-color: red; left: 0px; top: 0px; } | ||
| } | ||
| `}</style> | ||
| </BrowserWindow> | ||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.