Skip to content

Commit

Permalink
perf: optimize animation with will-change (#177)
Browse files Browse the repository at this point in the history
* perf: optimize animation with will-change

* test: update snapshot
  • Loading branch information
Kikobeats committed Jan 28, 2020
1 parent 1ee61c6 commit dde1aff
Show file tree
Hide file tree
Showing 7 changed files with 1,123 additions and 502 deletions.
2 changes: 2 additions & 0 deletions packages/react/src/components/Card/CardContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const Footer = styled('footer').attrs({ className: classNames.url })`
const Author = styled(CardText)`
opacity: 0.75;
transition: opacity ${transition.medium};
will-change: opacity;
.${classNames.main}:hover & {
opacity: 1;
Expand All @@ -95,6 +96,7 @@ const PoweredBy = styled('span').attrs({ title: 'microlink.io' })`
display: block;
margin-left: 15px;
transition: filter ${transition.medium}, opacity ${transition.medium};
will-change: filter, opacity;
&:not(:hover) {
filter: grayscale(100%);
opacity: 0.75;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const BottomControls = styled('div')`
justify-content: center;
align-items: center;
transition: opacity ${transition.medium};
will-change: opacity;
.${classNames.main}:not(:hover) & {
opacity: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const MediaButton = styled('div')`
backface-visibility: hidden;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
transition: transform ${transition.short};
will-change: transform;
> svg {
display: block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const ProgressBar = styled('div').attrs(({ progress }) => ({
bottom: 0;
background: #e1e8ed;
height: ${props => getProgressBarSize(props)}px;
transition: opacity ${transition.medium}, background ${transition.medium};
transition: background ${transition.medium};
will-change: background;
.${classNames.main}:hover & {
background: #fff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const OuterWrap = styled('div').attrs({ className: classNames.mediaControls })`
right: 0;
bottom: 0;
transition: background ${transition.long};
will-change: background;
.${classNames.main}:hover & {
background: rgba(0, 0, 0, 0.35);
Expand All @@ -39,6 +40,7 @@ const InnerWrap = styled('div')`
justify-content: center;
z-index: 2;
transition: opacity ${transition.medium};
will-change: opacity;
.${classNames.main}:not(:hover) & {
opacity: ${({ opacity = 0 }) => opacity};
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Card/CardWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const contrastStyle = ({ backgroundColor, color }) => css`
background-color: ${backgroundColor};
border-color: ${color};
transition-property: filter;
will-change: filter;
&&& {
color: ${color};
Expand All @@ -24,15 +25,14 @@ const contrastStyle = ({ backgroundColor, color }) => css`
const largeStyle = css`
flex-direction: column;
height: ${HEIGHT};
transition-property: background, border-color, height;
${media.mobile`
height: calc(${HEIGHT} * 7/9);
`};
`

const hoverStyle = css`
transition-property: background, border-color;
will-change: background, border-color;
&:hover {
background: #f5f8fa;
border-color: rgba(136, 153, 166, 0.5);
Expand Down
Loading

0 comments on commit dde1aff

Please sign in to comment.