Skip to content

Commit

Permalink
10. CSS Animation. Active key value
Browse files Browse the repository at this point in the history
  • Loading branch information
ApayRus committed Jun 26, 2022
1 parent 0bb616e commit f468ce3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
16 changes: 11 additions & 5 deletions components/Key.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ const Key = {
template: `
<div
:class="[
'key',
keyContent.code,
{ active: isActive },
{ shiftKeyPressed: isShift && shiftKey && !isActive }
]"
'key',
keyContent.code,
{ shiftKeyPressed: isShift && shiftKey && !isActive }
]"
@click="keyClick(keyContent)"
>
<div v-if="isActive" :class="['key', 'active', keyContent.code]">
<div>{{value}}</div>
</div>
<div class="main">{{main}}</div>
<div class="shifted">{{shifted}}</div>
</div>`,
Expand All @@ -57,6 +59,10 @@ const Key = {
},
isShift() {
return this.keyContent.code.includes('Shift')
},
value() {
const { main, shifted, code } = this.keyContent
return (this.shiftKey ? shifted : main) || code
}
},
methods: {
Expand Down
39 changes: 38 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,47 @@
font-size: 1.5rem;
cursor: pointer;
flex: 1;
position: relative;
}

.key.active {
background-color: red;
animation: pulse 1s;
/* position (4 lines) : */
position: absolute;
top: 0;
left: 0;
z-index: 2;

width: 100%;
height: 100%;

/* to compensate .key style: */
padding: -0.5rem;
margin: -0.2rem;

/* to center content vertically and horizontally: */
display: flex;
align-items: center;
justify-content: center;

transform-origin: center;
}

@keyframes pulse {
0% {
background-color: black;
transform: scale(100%);
}
30% {
transform: scale(130%);
}
80% {
transform: scale(130%);
}
100% {
background-color: red;
transform: scale(100%);
}
}

.row {
Expand Down

0 comments on commit f468ce3

Please sign in to comment.