Add button animation snippets

This commit is contained in:
Chalarangelo
2021-05-24 15:28:52 +03:00
parent 407ad20434
commit 98d7922675
4 changed files with 113 additions and 3 deletions

View File

@ -14,7 +14,7 @@ Creates a border animation on hover.
```css
.animated-border-button {
background-color: #141414;
background-color: #263059;
border: none;
color: #ffffff;
outline: none;
@ -33,13 +33,13 @@ Creates a border animation on hover.
}
.animated-border-button:before {
border-top: 2px solid #141414;
border-top: 2px solid #263059;
right: 0;
top: -4px;
}
.animated-border-button:after {
border-bottom: 2px solid #141414;
border-bottom: 2px solid #263059;
bottom: -4px;
left: 0;
}

View File

@ -0,0 +1,52 @@
---
title: Button swing animation
tags: animation,intermediate
---
Creates a swing animation on focus.
- Use an appropriate `transition` to animate changes to the element.
- Use the `:focus` pseudo-class to apply an `animation` that uses `transform` to make the element swing.
- Use `animation-iteration-count` to only play the animation once.
```html
<button class="button-swing">Submit</button>
```
```css
.button-swing {
color: #65b5f6;
background-color: transparent;
border: 1px solid #65b5f6;
border-radius: 4px;
padding: 0 16px;
cursor: pointer;
transition: all 0.2s ease-in-out;
}
.button-swing:focus {
animation: swing 1s ease;
animation-iteration-count: 1;
}
@keyframes swing {
15% {
transform: translateX(5px);
}
30% {
transform: translateX(-5px);
}
50% {
transform: translateX(3px);
}
65% {
transform: translateX(-3px);
}
80% {
transform: translateX(2px);
}
100% {
transform: translateX(0);
}
}
```

View File

@ -0,0 +1,29 @@
---
title: Button grow animation
tags: animation,beginner
---
Creates a grow animation on hover.
- Use an appropriate `transition` to animate changes to the element.
- Use the `:hover` pseudo-class to change the `transform` to `scale(1.1)`, growing the element when the user hovers over it.
```html
<button class="button-grow">Submit</button>
```
```css
.button-grow {
color: #65b5f6;
background-color: transparent;
border: 1px solid #65b5f6;
border-radius: 4px;
padding: 0 16px;
cursor: pointer;
transition: all 0.3s ease-in-out;
}
.button-grow:hover {
transform: scale(1.1);
}
```

View File

@ -0,0 +1,29 @@
---
title: Button shrink animation
tags: animation,beginner
---
Creates a shrink animation on hover.
- Use an appropriate `transition` to animate changes to the element.
- Use the `:hover` pseudo-class to change the `transform` to `scale(0.8)`, shrinking the element when the user hovers over it.
```html
<button class="button-shrink">Submit</button>
```
```css
.button-shrink {
color: #65b5f6;
background-color: transparent;
border: 1px solid #65b5f6;
border-radius: 4px;
padding: 0 16px;
cursor: pointer;
transition: all 0.3s ease-in-out;
}
.button-shrink:hover {
transform: scale(0.8);
}
```