Add 'scroll down' animation and hover

This commit is contained in:
Maciej Matuszewski 2018-01-14 18:34:07 +01:00
parent 7929de5e8e
commit 2d416bb5a7
6 changed files with 88 additions and 42 deletions

View File

@ -37,7 +37,9 @@
<a href="{{ hero.nextSectionLink.link }}" class="hero__scroll"> <a href="{{ hero.nextSectionLink.link }}" class="hero__scroll">
<div class="js-parallax" data-rellax-speed="0.2"> <div class="js-parallax" data-rellax-speed="0.2">
{{svg 'images/arrow-down.svg' class="hero__scroll__icon"}} {{svg 'images/arrow-down.svg' class="hero__scroll__icon"}}
<div class="hero__scroll__text">{{ hero.nextSectionLink.text }}</div> <div class="hero__scroll__text" data-title="{{ hero.nextSectionLink.text }}">
{{ hero.nextSectionLink.text }}
</div>
</div> </div>
</a> </a>

View File

@ -3,3 +3,42 @@
font-weight: 400; font-weight: 400;
text-transform: uppercase; text-transform: uppercase;
} }
/* element must have data-title property */
@mixin hoverDistortion() {
position: relative;
&::before,
&::after {
position: absolute;
top: 50%;
left: 50%;
z-index: -1;
width: 100%;
content: attr(data-title);
transform: translate(-50%, -50%);
transition: transform .7s cubic-bezier(0, 1.54, .4, 1.7);
}
&::before {
color: $color-red;
}
&::after {
color: $color-blue;
}
}
@mixin hoverDistortionActive() {
&::before {
$transform-val: calc(-50% - #{$distort-anim-size});
transform: translate($transform-val, $transform-val);
}
&::after {
$transform-val: calc(-50% + #{$distort-anim-size});
transform: translate($transform-val, $transform-val);
}
}

View File

@ -44,3 +44,4 @@ $title-font-family: 'Rubik Mono One', sans-serif;
$duration: .2s; $duration: .2s;
$header-height--mobile: 80px; $header-height--mobile: 80px;
$header-height--desktop: 95px; $header-height--desktop: 95px;
$distort-anim-size: 2px;

View File

@ -81,8 +81,18 @@ body {
cursor: pointer; cursor: pointer;
&__text { &__text {
@include hoverDistortion;
margin-top: 15px; margin-top: 15px;
} }
&__icon {
animation: scrollDown 3.5s infinite;
}
&:hover &__text {
@include hoverDistortionActive;
}
} }
} }

View File

@ -46,6 +46,8 @@ $_anim-size: 2px;
} }
&__link { &__link {
@include hoverDistortion();
position: relative; position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
@ -60,35 +62,8 @@ $_anim-size: 2px;
white-space: nowrap; white-space: nowrap;
} }
&__link::after, &__link.active {
&__link::before { @include hoverDistortionActive();
position: absolute;
top: 50%;
left: 50%;
z-index: -1;
content: attr(data-title);
transform: translate(-50%, -50%);
transition: transform .7s cubic-bezier(0, 1.54, .4, 1.7);
}
&__link::before {
color: $color-red;
}
&__link::after {
color: $color-blue;
}
&__link.active::before {
$transform-val: calc(-50% - #{$_anim-size});
transform: translate($transform-val, $transform-val);
}
&__link.active::after {
$transform-val: calc(-50% + #{$_anim-size});
transform: translate($transform-val, $transform-val);
} }
&__item--sub-nav { &__item--sub-nav {
@ -130,21 +105,13 @@ $_anim-size: 2px;
width: calc(100% - 20px); width: calc(100% - 20px);
} }
&__link:hover {
@include hoverDistortionActive();
}
&__link { &__link {
position: static; position: static;
flex-direction: row; flex-direction: row;
} }
&__link:hover::before {
$transform-val: calc(-50% - #{$_anim-size});
transform: translate($transform-val, $transform-val);
}
&__link:hover::after {
$transform-val: calc(-50% + #{$_anim-size});
transform: translate($transform-val, $transform-val);
}
} }
} }

View File

@ -37,3 +37,30 @@
transform-origin: 50% 50%; transform-origin: 50% 50%;
transition: transform $duration $easing 0s, visibility 0s $easing $duration; transition: transform $duration $easing 0s, visibility 0s $easing $duration;
} }
// @keyframes hovering {
// }
@keyframes scrollDown {
0% {
transform: translateY(0);
}
10% {
transform: translateY(5px);
}
15% {
transform: translateY(2px);
}
25% {
transform: translateY(5px);
}
50%,
100% {
transform: translateY(0);
}
}