Animation of Arrow with Click - css

i am absolute newbie and this is my first code:
.container_menu {
position: relative;
top: 0px;
left: 0px;
width: 25px;
height: 25px;
}
.container_menu .line-1 {
background-color: black;
width: 59%;
height: 2px;
position: absolute;
top: 50%;
left: 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
}
.container_menu .line-2 {
background-color: black;
width: 59%;
height: 2px;
position: absolute;
top: 50%;
right: 0;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
}
.container_menu:hover .line-1 {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.container_menu:hover .line-2 {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
<div class="container_menu">
<div class="line-1"></div>
<div class="line-2"></div>
</div>
How could I have a animation with click (Maybe JS?) and not with hover?
I will use it in a menu of a website.
I think I must use a JS Code. But I don't know, how I could realize. Perhaps you can help me, many thanks.
Code from https://codepen.io/defaultdave/pen/baXLPQ

https://codepen.io/Tanded/pen/OqVBPE
<div class="container" onclick="fnc(this)">
<div class="line-1"></div>
<div class="line-2"></div>
</div>
function fnc(el){
el.classList.toggle("clicked");
}
add a small js function to toggle class and edit css to animate lines when they have clicked class instead of hover
&:hover -> &.clicked on line 53

Related

Removing class in HTML is not capturing correct CSS styling

Using Bootstrap as my default CSS, I also created a custom .css file I made that creates a loading screen when my webpage is processing the information. Basically, my loading screen is hiding in the background and I use javascript to bring it to the front for any triggers.
Here is the CSS code:
#loading-page.loading {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1000;
}
#loading-page.loading #loading-page-icon {
display: block;
position: relative;
left: 50%;
top: 50%;
width: 150px;
height: 150px;
margin: -75px 0 0 -75px;
border-radius: 50%;
border: 3px solid transparent;
border-top-color: #3498db;
z-index: 1001;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#loading-page.loading #loading-page-icon:before {
content: "";
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border-radius: 50%;
border: 3px solid transparent;
border-top-color: #e74c3c;
-webkit-animation: spin 3s linear infinite;
animation: spin 3s linear infinite;
}
#loading-page.loading #loading-page-icon:after {
content: "";
position: absolute;
top: 15px;
left: 15px;
right: 15px;
bottom: 15px;
border-radius: 50%;
border: 3px solid transparent;
border-top-color: #f9c922;
-webkit-animation: spin 1.5s linear infinite;
animation: spin 1.5s linear infinite;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg)
}
100% {
-webkit-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg)
}
}
#keyframes spin {
0% {
-webkit-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg)
}
100% {
-webkit-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg)
}
}
#loading-page.loading .loading-curtain {
position: fixed;
top: 0;
width: 51%;
height: 100%;
background: #5c5c5c;
z-index: 1000;
}
#loading-page.loading .loading-curtain.section-left {
left: 0;
}
#loading-page.loading .loading-curtain.section-right {
right: 0;
}
/* Once the page loads */
#loading-page:not(.loading) {
visibility: hidden;
-webkit-transform: translateY(-100%);
-ms-transform: translateY(-100%);
transform: translateY(-100%) -webkit-transition: all 0.3s 1s ease-out;
transition: all 0.3s 1s ease-out;
}
#loading-page:not(.loading) #loading-page-icon {
opacity: 0;
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#loading-page:not(.loading) .loading-curtain.section-left {
-webkit-transform: translateX(-100%);
-ms-transform: translateX(-100%);
transform: translateX(-100%);
-webkit-transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
#loading-page:not(.loading) .loading-curtain.section-right {
-webkit-transform: translateX(100%);
-ms-transform: translateX(100%);
transform: translateX(100%);
-webkit-transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
Here is my HTML
<body>
<div id="loading-page">
<div id="loading-page-icon"></div>
<div class="loading-curtain section-left"></div>
<div class="loading-curtain section-right"></div>
</div>
...[other html code]
</body>
And then here is my Javascript I use to remove the class on my div#loading-page
$(document).ready(function() {
/*
When a page fully loads, remove the .loading class
*/
$('#loading-page')
.removeClass('loading')
})
$(document).on(
"submit",
[
'form.search',
],
function() {
/*
Event Listener- anytime the search form is submitted, display the
loading screen.
*/
$('#loading-page')
.addClass('loading')
})
The only problem I have with my CSS code is for some reason, my transition animation will not work (where you see 'Once the page loads' comment in .css) - as if I performed a .hide() on #loading-page than removing the class. I'm pretty sure the CSS is getting ignored. I even tried to force the styling by trying to use the :not('loading') operator. Besides the animation not working, the loading screen does pop up and then goes away once the document is ready as expected. Any help why my CSS is getting ignored?
Thank you
Adding and removing .loading toggles the visibility property - which can't be transitioned. Something is either hidden or not. If you want to fade in the element, use opacity, and possibly pointer-events so the invisible-but-still present element doesn't capture click events.

Why is there a strange "thinning" effect visible on these span tags after the transition has finished?

Despite using normalize.css when I try to make this navigation icon, originally from Jesse Couch, thinner, then after the transition the span tags seems to get a second effect applied to them, making them a tiny tad more thinner. Why is this happening? Sorry I cannot really word this better but please see for yourself. Firefox version 28 up to 50 shows this effect, Chrome latest version however does not and not tested this in Opera or IE11/Edge.
* {
margin: 0;
padding: 0;
}
/* normalize.css included */
#nav-icon {
width: 60px;
height: 45px;
position: relative;
margin: 50px auto;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
cursor: pointer;
}
/* When I change the default value of 9px to something lower there is a strange "thinning" effect visible on the span tag after about half a second, why?*/
#nav-icon span {
display: block;
position: absolute;
height: 5px; /* 9px is the default value, lowering this has a strange after effect on the span tags, why? */
width: 100%;
background: #d3531a;
border-radius: 5px; /* 9px is the default value, lowering this has a strange after effect on the span tags, why? */
opacity: 1;
left: 0;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
#nav-icon span:nth-child(1) {
top: 0px;
}
#nav-icon span:nth-child(2),#nav-icon span:nth-child(3) {
top: 18px;
}
#nav-icon span:nth-child(4) {
top: 36px;
}
#nav-icon.open span:nth-child(1) {
top: 18px;
width: 0%;
left: 50%;
}
#nav-icon.open span:nth-child(2) {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
#nav-icon.open span:nth-child(3) {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
#nav-icon.open span:nth-child(4) {
top: 18px;
width: 0%;
left: 50%;
}

Transition on transform translate not working

Does anybody know how to animate the transition the right way? As you can see in the code, after a small delay the div has to move up. I couldn't get it to work.
Codepen:
http://codepen.io/thijs-webber/pen/jqgPrK
HTML:
<div class="test">
test
</div>
CSS:
.test{
background-color: lime;
width: 100px;
margin: 0 auto;
margin-top: 100px;
height: 100px;
padding: 10px;
text-align: center;
line-height: 100px;
-moz-transform: translate(0, -100px);
-webkit-transform: translate(0, -100px);
-o-transform: translate(0, -100px);
-ms-transform: translate(0, -100px);
transform: translate(0, -100px);
transition: transform 1s ease-out;
-webkit-transition: transform 1s ease-out;
-moz-transition: transform 1s ease-out;
-ms-transition: transform 1s ease-out;
-o-transition: transform 1s ease-out;
transition-delay: 1s;
}
Using a trigger is one idea, but If you don't want any trigger, you just have to use CSS3 keyframes
Here's your code with it:
.test{
background-color: lime;
width: 100px;
margin: 0 auto;
margin-top: 100px;
height: 100px;
padding: 10px;
text-align: center;
line-height: 100px;
-moz-transform: translate(0, -100px);
-webkit-transform: translate(0, -100px);
-o-transform: translate(0, -100px);
-ms-transform: translate(0, -100px);
transform: translate(0, -100px);
-moz-transform: translate(0, -100px);
-webkit-transform: translate(0, -100px);
-o-transform: translate(0, -100px);
-ms-transform: translate(0, -100px);
transform: translate(0, -100px);
animation-name: moveUp;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 1s;
}
#keyframes moveUp {
0% {
transform: translate(0);
}
100% {
transform: translate(0, -100px);
}
}
<div class="test">
test
</div>
I added the necessary animations styles, such as name (used in the keyframes), how many times should this animation occur, the timing-function and the duration, respectively:
animation-name: moveUp;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 1s;
I hope this helps!
It works, but due to there is no trigger, you can't observe its movement. When you loaded the page, transition had already been completed. If you want to observe transition, there should be a trigger like hover or you can use animation css method. In snippet hover is a trigger. As I said if you want it to work when page is opened, you can use animation.
.test{
background-color: lime;
width: 100px;
margin: 0 auto;
margin-top: 100px;
height: 100px;
padding: 10px;
text-align: center;
line-height: 100px;
transition: transform 1s ease-out;
-webkit-transition: transform 1s ease-out;
-moz-transition: transform 1s ease-out;
-ms-transition: transform 1s ease-out;
-o-transition: transform 1s ease-out;
}
.test:hover{
-moz-transform: translate(0, -100px);
-webkit-transform: translate(0, -100px);
-o-transform: translate(0, -100px);
-ms-transform: translate(0, -100px);
transform: translate(0, -100px);
}
<div class="test">
test
</div>

Card flipping by css transform, which properties need animation?

Demo
The core of the flipping animation is on transform: rotateY(180deg);. Of course transition is needed as well for animation. I copied the code from another site, which uses transition: all ...;.
For some reason, some properties (eg: height, width) must have no transition. But I don't know which properties are essential for flipping animation.
Anyone knows how I can change the line transition: all ...; to keep the flipping animation, while not affecting unrelated properties?
This page explains everything and has live demos. I've just needed a simple Google search. :)
http://desandro.github.io/3dtransforms/docs/card-flip.html
Apparently, the trick is to use
transition: transform 1s;
change the style when you :hover on parent
.card {
-moz-perspective: 600;
-webkit-perspective: 600;
perspective: 600;
position: relative;
height: 200px;
width: 200px;
}
.card .side {
overflow: hidden;
position: absolute;
top: 0;
left: 0;
width: inherit;
height: inherit;
-moz-box-shadow: 0 0 5px #888;
-webkit-box-shadow: 0 0 5px #888;
box-shadow: 0 0 5px #888;
-moz-transform-style: perserve-3d;
-webkit-transform-style: perserve-3d;
transform-style: perserve-3d;
-moz-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
}
.card .side.front {
z-index: 900;
-moz-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
.card:hover .side.front {
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.card .side.back {
z-index: 800;
-moz-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.card:hover .side.back {
z-index: 800;
-moz-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
<article class="card">
<section class="side front">front</section>
<section class="side back">back</section>
</article>

CSS delay transition

The following CSS works fine, however I am trying to add 1 or 2 seconds delay to the flip back effect. When you hover it the '.back' is visible and then when you leave the area the '.front'. I would like to add a delay so that when you leave the area it takes one or two seconds before it goes back to '.front' Is that possible?
.panel {
width: 250px!important;
height: 250px;
margin: auto!important;
position: relative;
-webkit-perspective:1000px;
}
.card {
width: 100%!important;
height: 100%;
-o-transition: all .5s;
-ms-transition: all .5s;
-moz-transition: all .5s;
-webkit-transition: all .5s;
transition: all .5s;
-webkit-backface-visibility: hidden;
-ms-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0px;
left: 0px;
}
.front {
z-index: 2;
}
.back {
background-color:#fff;
z-index: 1;
-webkit-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
-moz-transform: rotateY(-180deg);
transform: rotateY(-180deg);
transition-delay: 2s;
}
.back p{
margin-top: 90px;
font-size: 20px;
text-align:center;
}
.panel:hover .front {
z-index: 1;
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
-webkit-transition:-webkit-transform 1s;
transition:transform 1s;
}
.panel:hover .back {
z-index: 2;
-webkit-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
-moz-transform: rotateY(0deg);
transform: rotateY(0deg);
-webkit-transition:-webkit-transform 1s;
transition:transform 1s;
transition-delay: 2s;
}
HTML
<li class="panel"><img class="front card" src="{{image}}" /><div class="back card"><p>{{model.user.full_name}}</p></div></li>
Add the transition-delay to .card - fiddle
.card {
-o-transition: all .5s 2s;
-ms-transition: all .5s 2s;
-moz-transition: all .5s 2s;
-webkit-transition: all .5s 2s;
transition: all .5s 2s;
}
.panel .front {
transition: all 2s;
}
You have to put the effect on the element in order to have it transition back without hovering on it.

Resources