CSS Transitions on menu items not working - css

it's the first time I'm using css transitions/transformations and it's not working out that well.
I'm simply trying to translate from bottom to position each entry of a toggled menu, but I'm getting strange results.
When I run the code within my app it executes the transition only on the first item of the list instead of all items.
When I run the same code from jsfiddle the transition doesn't work at all on any item.
Please see my jsfiddle here
I've looked at the documentation, at so many different examples and at many other solutions for similar issues. I've tried them all, defying height, removing display, but nothing seems to make any difference
<header>
<a id="menu">
<i class="fas fa-bars"></i>
</a>
</header>
<nav class="nav nav-sm">
<ul class="nav__list">
<li class="nav__item">ABOUT</li>
<li class="nav__item">SKILLS</li>
<li class="nav__item">WORKS</li>
</ul>
</nav>
header {
width: 100%;
z-index: 3;
display: flex;
align-items: center;
justify-content: right;
background-color: #68c7c1;
min-height: 56px;
transition: min-height 0.3s;
}
header #menu {
margin-left: auto;
margin-right:10px;
color: #eceeef;
font-size: 2em;
}
.nav {
width: 100%;
height: auto;
position: absolute;
z-index: 2;
display: flex;
flex-wrap: wrap;
background-color: #68c7c1;
}
.nav-sm, .nav-lg { display: none; }
.nav-sm.open {
display: flex;
flex-wrap: wrap;
align-items: center;
height: calc(100% - 56px);
margin-top: -2px;
}
.nav__list, .nav__item { width: 100%; }
.nav__list {
display: flex;
flex-wrap: wrap;
}
.nav__item {
height:50px;
display: flex;
flex-wrap: nowrap;
justify-content: center;
}
.nav__item a {
text-decoration: none;
text-align: center;
font-size: 1.2em;
color: #eceeef;
}
.nav-sm .nav__list .nav__item {
color: red;
transition: -transform 3s ease-in-out;
-moz-transition: -moz-transform 3s ease-in-out;
-webkit-transition: -webkit-transform 3s ease-in-out;
}
.nav-sm.open .nav__item {
padding-bottom: 80px;
font-size: 2em;
transform: translate(0,-50px);
-moz-transform: translate(0,-50px);
-webkit-transform: translate(0,-50px);
}
An example of what I'm trying to achieve is something similar to the menu of this portfolio.

What are you exactly trying to do ? animation ? transition when clicked ?
here is an example of how to write animation via css :
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: example;
animation-duration: 4s;
}
/* Standard syntax */
#keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}

The way they did it in the example you provided is with js with some animation library, if you'd inspect their code you can see it happening.
To achieve this animation we'll have to make use of the delay property either way using animation or transition and you will have to add a delay on every item, so when you add a new item to the menu you'll have to add a delay to that item, we can automate this using js
Here's a demo using transition, the timing function, delay and the duration will need extra care, i'll leave that you to adjust to your desired end result.
var menu = document.querySelector("#menu");
var nav = document.querySelector(".nav-sm");
function openMenu(e) {
nav.classList.toggle("open");
e.stopPropagation();
};
function closeMenu(e) {
nav.classList.remove("open");
};
menu.addEventListener("click", openMenu);
#menu {
font-size: 2rem;
margin: 30px;
display: flex;
flex-direction: column;
align-items: flex-end;
}
ul {
border: 1px solid;
list-style: none;
padding: 10px;
margin: 30px;
}
li {
opacity: 0;
transform: translateY(5px);
margin: 20px 0;
text-align: center;
}
a {
text-decoration: none;
padding: 5px 30px;
background: dodgerblue;
color: white;
}
.open li:nth-child(1) {
transition: all .4s linear;
}
.open li:nth-child(2) {
transition: all .4s .2s linear;
}
.open li:nth-child(3) {
transition: all .4s .4s linear;
}
.open li {
opacity: 1;
transform: translateY(0px);
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">
<div id="menu">
<i class="fas fa-bars"></i>
</div>
<ul class="nav-sm">
<li>ABOUT</li>
<li>SKILLS</li>
<li>WORKS</li>
</ul>

So, I managed to achieve what I wanted by mixing both suggestions :)
Please see the result in this jsfiddle.
The reason why the transition wasn't working it's because I'm using display:none on the .nav. This problem is resolved by using animation instead and applying a delay on each list element.
Thank you for both answers!
header {
width: 100%;
z-index: 3;
display: flex;
align-items: center;
justify-content: right;
background-color: #68c7c1;
min-height: 56px;
transition: min-height 0.3s;
}
header #menu {
margin-left: auto;
margin-right:10px;
color: #eceeef;
font-size: 2em;
}
.nav {
width: 100%;
height: auto;
z-index: 2;
display: flex;
flex-wrap: wrap;
background-color: #68c7c1;
}
.nav-sm, .nav-lg { display: none; }
.nav-sm.open {
display: flex;
flex-wrap: wrap;
align-items: center;
height: calc(100% - 56px);
margin-top: -2px;
}
.nav__list, .nav__item { width: 100%; }
.nav__list {
display: flex;
flex-wrap: wrap;
}
.nav__item {
height:50px;
display: flex;
flex-wrap: nowrap;
justify-content: center;
}
.nav__item a {
text-decoration: none;
text-align: center;
font-size: 1.2em;
color: #eceeef;
}
.nav-sm.open {
-webkit-animation: slide-down .3s linear;
-moz-animation: slide-down .3s linear;
}
.nav-sm.open .nav__item{
padding-bottom: 80px;
font-size: 2em;
}
.nav-sm.open .nav__item:nth-child(1) {
-webkit-animation: slide-down .3s .1s linear;
-moz-animation: slide-down .3s .1s linear;
}
.nav-sm.open .nav__item:nth-child(2) {
-webkit-animation: slide-down .3s .2s linear;
-moz-animation: slide-down .3s .2s linear;
}
.nav-sm.open .nav__item:nth-child(3) {
-webkit-animation: slide-down .3s .3s linear;
-moz-animation: slide-down .3s .3s linear;
}
#-webkit-keyframes slide-down {
0% { opacity: 0; -webkit-transform: translateY(-100%); }
100% { opacity: 1; -webkit-transform: translateY(0%); }
}
#-moz-keyframes slide-down {
0% { opacity: 0; -moz-transform: translateY(-100%); }
100% { opacity: 1; -moz-transform: translateY(0%); }
}

Related

How to achieve reverse animation on mouse out using keyframes

I am trying to add scale up animation on a div.
I tried this using both transition and animation property.
In case of transition you can notice that when hovered out the animation is smoothly reversed. However, this doesn't happen when using animation property (the div transitions back to initial width instantly)
Can someone tell me:
Why this behaviour in case of animation only?
How can I achieve the same using animation property?
.animations {
display: flex;
padding: 80px;
width: 100vw;
height: 100vh;
background: linear-gradient(to right, #f3d2d2, white, #cee5f3);
}
.animations > div {
width: 200px;
height: 200px;
margin: 40px;
font-family: system-ui;
display: flex;
flex-direction: column;
align-items: center;
}
.animations > p {
color: black;
flex: 1;
text-align: center;
}
.animations .animated-box {
flex: 2;
width: 100%;
background: grey;
cursor: pointer;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.animated-box.scale-up {
}
.animated-box.scale-up:hover {
animation: scale-up 0.5s ease forwards;
transform: scale(1);
}
.animated-box.scale-up-with-mouseout {
transition: transform 0.5s ease-in;
}
.animated-box.scale-up-with-mouseout:hover {
transform: scale(1.2);
}
#keyframes scale-up {
100% {transform: scale(1.2)};
0%{transform: scale(1)};
}
<div class="animations">
<div>
<div class="animated-box scale-up">Hover me</div>
<p>Scale up (with keyframes)</p>
</div>
<div>
<div class="animated-box scale-up-with-mouseout">Hover me</div>
<p>Scale up (with transition)</p>
</div>
</div>
invert this part only
#keyframes scale-up {
100% {transform: scale(1.2)};
0%{transform: scale(1)};
}
and to fix the animation when mouse out add a new keyframe
#keyframes scale-down {
0% {transform: scale(1.2)};
100%{transform: scale(1)};
}
and apply it to the class .animated-box.scale-up
.animated-box.scale-up {
animation: scale-down 0.5s ease forwards;
}
.animations {
display: flex;
padding: 80px;
width: 100vw;
height: 100vh;
background: linear-gradient(to right, #f3d2d2, white, #cee5f3);
}
.animations > div {
width: 200px;
height: 200px;
margin: 40px;
font-family: system-ui;
display: flex;
flex-direction: column;
align-items: center;
}
.animations > p {
color: black;
flex: 1;
text-align: center;
}
.animations .animated-box {
flex: 2;
width: 100%;
background: grey;
cursor: pointer;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.animated-box.scale-up {
animation: scale-down 0.5s ease forwards;
}
.animated-box.scale-up:hover {
animation: scale-up 0.5s ease forwards;
}
.animated-box.scale-up-with-mouseout {
transition: transform 0.5s ease-in;
}
.animated-box.scale-up-with-mouseout:hover {
transform: scale(1.2);
}
#keyframes scale-up {
100% {transform: scale(1.2)};
0%{transform: scale(1)};
}
#keyframes scale-down {
0% {transform: scale(1.2)};
100%{transform: scale(1)};
}
<div class="animations">
<div>
<div class="animated-box scale-up">Hover me</div>
<p>Scale up (doesn't work)</p>
</div>
<div>
<div class="animated-box scale-up-with-mouseout">Hover me</div>
<p>Scale up (works)</p>
</div>
</div>

My css animation code does not work smoothly

Hello I want to have smooth typing animation in css but my code doesn't work smoothly
My text just appears on the screen suddenly
Here's my css code:
.title-text {
white-space: nowrap;
overflow: hidden;
animation: typing 4s steps(40) 1s 1 normal both;
}
#keyframes typing {
from {
width: 0;
}
to {
width: fit-content;
}
}
Thanks in advance
You have to pass specific width. The fit-content seems to be not working.
.title-text {
white-space: nowrap;
overflow: hidden;
animation: typing 4s steps(40) 1s 1 normal both;
}
#keyframes typing {
from {
width: 0;
}
to {
width: 200px;
}
}
Try this code
.title-text{
white-space: nowrap;
overflow: hidden;
animation: typing 1s steps(40) 1s 4 normal both;
}
#keyframes typing{
from{
width: 0;
}to{
width: 100px;
}
}
You can achieve this with transform: scaleX(n) where n transitions from 0 to 1:
.title-text{
white-space: nowrap;
overflow: hidden;
animation: typing .4s steps(40) 0s 1 normal both;
display:inline-block;
transform-origin:left;
}
#keyframes typing{
from{
transform: scaleX(0);
}to{
transform: scaleX(1)
}
}
<div class="title-text">This is the title</div>
Maybe you can try with this:
.title-text h1 {
overflow: hidden;
border-right: .15em solid orange;
white-space: nowrap;
margin: 0 auto;
letter-spacing: .15em;
animation:
typing 3.5s steps(30, end),
blink-caret .5s step-end infinite;
}
#keyframes typing {
from { width: 0 }
to { width: 100% }
}
#keyframes blink-caret {
from, to { border-color: transparent }
50% { border-color: orange }
}
HTML:
<div class="title-text">
<h1>This is a Heading.</h1>
</div>

CSS Animations - Dynamic Curved Lines Between Divs That Move Up & Down

I have dots moving up and down with a CSS animation, however I'd like to draw a dynamic curved line between them to create "Curved Chart" type look (a chart isn't the actual end goal, just the visual effect). How would I achieve this? Here's what I currently have:
The HTML Code:
<ul>
<li><span class="ball1"></span></li>
<li><span class="ball2"></span></li>
<li><span class="ball3"></span></li>
<li><span class="ball4"></span></li>
<li><span class="ball5"></span></li>
<li><span class="ball6"></span></li>
<li><span class="ball7"></span></li>
<li><span class="ball8"></span></li>
<li><span class="ball9"></span></li>
<li><span class="ball10"></span></li>
</ul>
The CSS Code:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: white;
}
ul {
width: 340px;
height: 80px;
display: grid;
grid-template-columns: repeat(10, 1fr);
}
li {
display: flex;
justify-content: center;
position: relative;
}
li:before {
content: '';
width: 6px;
height: 90px;
position: absolute;
top: -5px;
border-radius: 90px;
}
span {
width: 20px;
height: 20px;
background: blue;
border-radius: 50%;
box-shadow: 0 0 20px -5px rgba(0, 0, 0, 0.3);
display: block;
animation: move 3s ease-in-out infinite alternate;
}
span.ball1 {
animation-delay: 0.25s;
}
span.ball2 {
animation-delay: 0.5s;
}
span.ball3 {
animation-delay: 0.75s;
}
span.ball4 {
animation-delay: 1s;
}
span.ball5 {
animation-delay: 1.25s;
}
span.ball6 {
animation-delay: 1.5s;
}
span.ball7 {
animation-delay: 1.75s;
}
span.ball8 {
animation-delay: 2s;
}
span.ball9 {
animation-delay: 2.25s;
}
span.ball10 {
animation-delay: 2.5s;
}
#keyframes move {
100% {
transform: translateY(58px);
}
}
Code Pen:
https://codepen.io/anon/pen/JwxJxO
Any help would be super useful, thank you!
You can add line between each circle to simulate such effect.
Here is a non-perfect example where I also used skew transformation to make the effect looks better (adjust the different value to get a perfect result like you want)
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: white;
}
ul {
width: 340px;
height: 80px;
display: grid;
grid-template-columns: repeat(10, 1fr);
}
li {
display: flex;
justify-content: center;
position: relative;
}
span {
width: 20px;
height: 20px;
background: blue;
border-radius: 50%;
box-shadow: 0 0 20px -5px rgba(0, 0, 0, 0.3);
display: block;
animation: move 3s ease-in-out infinite alternate;
position:relative;
transform: translateY(-29px);
}
li:not(:last-child) span::before {
content:"";
position:absolute;
top:50%;
left:100%;
width:20px;
height:2px;
background:blue;
animation-delay:inherit;
animation: skew 3s ease-in-out infinite alternate;
}
span.ball1 {
animation-delay: 0.25s;
}
span.ball2 {
animation-delay: 0.5s;
}
span.ball3 {
animation-delay: 0.75s;
}
span.ball4 {
animation-delay: 1s;
}
span.ball5 {
animation-delay: 1.25s;
}
span.ball6 {
animation-delay: 1.5s;
}
span.ball7 {
animation-delay: 1.75s;
}
span.ball8 {
animation-delay: 2s;
}
span.ball9 {
animation-delay: 2.25s;
}
span.ball10 {
animation-delay: 2.5s;
}
#keyframes move {
0% {
transform: translateY(-29px);
}
100% {
transform: translateY(29px);
}
}
#keyframes skew {
0% {
transform: skewY(13deg);
}
30% {
transform: skewY(10deg);
}
70% {
transform: skewY(-10deg);
}
100% {
transform: skewY(-13deg);
}
}
<ul>
<li><span class="ball1"></span></li>
<li><span class="ball2"></span></li>
<li><span class="ball3"></span></li>
<li><span class="ball4"></span></li>
<li><span class="ball5"></span></li>
<li><span class="ball6"></span></li>
<li><span class="ball7"></span></li>
<li><span class="ball8"></span></li>
<li><span class="ball9"></span></li>
<li><span class="ball10"></span></li>
</ul>
You can achieve this with kind of animations with canvas.
here's an example I found on codepen, which might be useful for your problem: https://codepen.io/nicolaszamarreno/pen/yXzGgG

image height inside div container

I have a problem with my image which is inside a div.
This div with swiper__content class gives kind of bottom padding to the image and I can't see what cause this effect. I have a 100% height with no padding or margin so it might fit in the div
.no-padding{
padding: 0px 0px !important;
}
.swiper {
margin: 0 auto 50px;
width: 40%;
text-align: center;
padding: 10px 20px;
font-size: 10vw;
line-height: 1;
position: relative;
overflow: hidden;
text-transform: uppercase;
font-family: "Impact";
cursor: pointer;
}
.swiper__content {
color: transparent;
display: block;
}
.swiper .swiper__content img{
opacity: 0;
width: 100%;
height: 100%;
transition: opacity 0s ease-in 0.5s;
-moz-transition: opacity 0s ease-in 0.5s;
-webkit-transition: opacity 0s ease-in 0.5s;
-o-transition: opacity 0s ease-in 0.5s;
}
.swiper__bar, .swiper__bar--right {
width: 100%;
height: 100%;
background: orange;
display: block;
position: absolute;
top: 0;
left: 0;
transform: translateX(-100%);
transition: 1s ease-in-out;
}
.swiper__bar--right {
transform: translateX(100%);
}
.swiper.revealed .swiper__content {
animation-name: kf-font-reveal;
animation-duration: 1s;
color: orange;
}
.swiper.revealed .swiper__content img{
opacity: 1;
}
<div class="swiper no-padding revealed">
<div class="swiper__content">
<img src="http://lorempicsum.com/futurama/350/200/1">
</div>
<span class="swiper__bar--right"></span>
</div>
Is there a way to remove that ?
Set line-height: 0 for your swiper class.
.no-padding{
padding: 0px 0px !important;
}
.swiper {
margin: 0 auto 50px;
width: 40%;
text-align: center;
padding: 10px 20px;
font-size: 10vw;
line-height: 0;
position: relative;
overflow: hidden;
text-transform: uppercase;
font-family: "Impact";
cursor: pointer;
}
.swiper__content {
color: transparent;
display: block;
}
.swiper .swiper__content img{
opacity: 0;
width: 100%;
height: 100%;
transition: opacity 0s ease-in 0.5s;
-moz-transition: opacity 0s ease-in 0.5s;
-webkit-transition: opacity 0s ease-in 0.5s;
-o-transition: opacity 0s ease-in 0.5s;
}
.swiper__bar, .swiper__bar--right {
width: 100%;
height: 100%;
background: orange;
display: block;
position: absolute;
top: 0;
left: 0;
transform: translateX(-100%);
transition: 1s ease-in-out;
}
.swiper__bar--right {
transform: translateX(100%);
}
.swiper.revealed .swiper__content {
animation-name: kf-font-reveal;
animation-duration: 1s;
color: orange;
}
.swiper.revealed .swiper__content img{
opacity: 1;
}
<div class="swiper no-padding revealed">
<div class="swiper__content">
<img src="http://lorempicsum.com/futurama/350/200/1">
</div>
<span class="swiper__bar--right"></span>
</div>

Why does my CSS animation not work on my sidebar?

Good Day, I'm trying to create a slidedown menu using some JS and CSS but it's not working. Here's the fiddle link:
ul.show-child{
height: auto;
display: block;
-webkit-transition: height 1s ease;
-moz-transition: ease-in 2s none;
-ms-transition: ease-in 2s none;
-o-transition: ease-in 2s none;
transition: ease-in 2s none;
}
https://jsfiddle.net/gkrja9jy/
What I want to do, is to add some cool animation when I show the hidden div. By the way, I just copied the transition effect from this site
There is a pure CSS solution. I corrected your example. Make sure that you write correct HTML code. Here is the new code and a fiddle:
HTML code:
<ul class="custom-sidebar">
<li>
Accountancy
</li>
<li>
Grade School
<ul>
<li>Goals and Objectives</li>
<li>Clubs and Orgs</li>
<li>Photo Gallery</li>
<li>Summer Tutorial</li>
</ul>
</li>
</ul>
CSS code:
li ul {
display: block;
height: 0px;
overflow: hidden;
-webkit-transition: all 0.25s ease-in-out;
-moz-transition: all 0.25s ease-in-out;
-ms-transition: all 0.25s ease-in-out;
-o-transition: all 0.25s ease-in-out;
transition: all 0.25s ease-in-out;
}
li:hover ul {
height: 100px;
display: block;
}
.custom-sidebar a,.custom-sidebar a:visited {
color: #0f5882;
display: block;
font-weight: bold;
height: 25px;
margin-left: -23px;
padding-left: 23px;
vertical-align: middle;
width: 100% !important;
}
.custom-sidebar li {
list-style: outside none none;
padding-left: 17px;
}
.custom-sidebar li a {
background-color: #ebecec;
border-left: 6px solid #116b9e;
padding-top: 2px;
margin-bottom: 8px;
}
https://jsfiddle.net/u6yrL0a0/2/
It is usually best to avoid JavaScript if it is not needed.
yo can use jquery to create the animation like this:
var jq=jQuery.noConflict();
jq(document).ready(function(){
jq('.menu-div').hover(function(){
if(jq(this).children(":first").hasClass('has-child')){
var thisx = jq(this).children(":first");
thisx.next('ul').slideDown(1000);
}
});
});
jq(document).ready(function(){
jq('.menu-div').mouseleave(function(){
if(jq(this).children(":first").hasClass('has-child')){
var thisx = jq(this).children(":first");
thisx.next('ul').slideUp(1000);
}
});
});
and the css will be like this :
ul.hide-child{
display: none;
overflow: hidden;
}
ul li ul{
-webkit-transition: all 1s;
-moz-transition: all 1s ;
transition: all 1s;
display:none;
height:auto;
}
.custom-sidebar .post-link,.post-link:visited{
color: #0f5882;
display: block;
font-weight: bold;
height: 25px;
margin-left: 0px;
padding-left: 23px;
vertical-align: middle;
width: 100% !important;
}
.custom-sidebar li{
background-color: #ebecec;
border-left: 6px solid #116b9e;
list-style: outside none none;
margin-bottom: 0px;
padding-left: 17px;
padding-top: 2px;
}
https://jsfiddle.net/gkrja9jy/5/

Resources