Is there a way to get this CSS code:
/** Swing **/
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
#-webkit-keyframes swing {
20%, 40%, 60%, 80%, 100% { -webkit-transform-origin: top center; }
20% { -webkit-transform: rotate(15deg); }
40% { -webkit-transform: rotate(-10deg); }
60% { -webkit-transform: rotate(5deg); }
80% { -webkit-transform: rotate(-5deg); }
100% { -webkit-transform: rotate(0deg); }
}
#keyframes swing {
20% { transform: rotate(15deg); }
40% { transform: rotate(-10deg); }
60% { transform: rotate(5deg); }
80% { transform: rotate(-5deg); }
100% { transform: rotate(0deg); }
}
.swing {
-webkit-transform-origin: top center;
transform-origin: top center;
-webkit-animation-name: swing;
animation-name: swing;
}
/****/
Generated from this website: https://coveloping.com/tools/css-animation-generator
To work only when hovering over an element?
I added:
.swing:hover {
-webkit-transform-origin: top center;
transform-origin: top center;
-webkit-animation-name: swing;
animation-name: swing;
}
Myself and it's not working.
Oh... And I'm trying to avoid using javascript/jQuery so the page will load faster..
Demo
Use the animation-play-state:running; on :hover
so that it plays while hovering over.
Not hovered element should then be : animation-play-state:paused; so its not running without hover.
Setting the animation-iteration-count:infinite; makes the animation run infinite (as long as you hover in this case).
Related
I recently found a flying bird animation that I have been attempting to implement into one of my recent projects. I have attempted to reciprocate the same exact animation, yet the animation appears to be broken on safari browsers (both mobile and desktop). I am approximately 95% certain that most of my css is correct, and that every property that requires it, has the -webkit prefix for safari.
With all that said, I have provided below a link to a Codepen that contains my exact code for the animation. As I mentioned before, if you open up the animation on Google Chrome, it works perfectly fine. Yet, when it is opened up on Safari, the animation acts completely different. Here are the primary issues I am noticing:
The 'Flying' animation appears to not be scrolling the bird background image properly(as this animation is meant to act like a flip book), which results in a previous frame of the bird appearing.
On Chrome, when the window is resized, the birds flight path adjusts to the width of the window, as I set the 'fly-across-1' animation (uses the transform property) to be responsive to the view window width. However, when you resize (try expanding the window) a safari window, the birds 'flight' does not reach the end of the window.
Not sure if any of this makes sense, but I have completely run out of mental capacity trying to adjust for the issues myself. If anyone has any idea what I am missing or has any suggestions, I would greatly appreciate the help. Thanks again.
Here is the Codepen
For reference, here is the css code:
.container {
position: relative;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
min-height: 35rem;
}
.bird-box {
position: absolute;
top: 20%;
left: -10%;
transform: translateX(-10vw);
-webkit-transform: translateX(-10vw);
will-change: transform;
}
.bird-box-one {
animation: fly-across-1 7s linear infinite;
-webkit-animation: fly-across-1 7s linear infinite;
}
.bird {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/174479/bird-cells-new.svg);
background-size: auto 100%;
width: 22px;
height: 31.25px;
will-change: background-position;
animation: flying;
-webkit-animation: flying;
animation-timing-function: steps(10);
-webkit-animation-timing-function: steps(10);
animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
}
.bird-one {
animation-duration: 1.3s;
-webkit-animation-duration: 1.3s;
animation-delay: -0.5s;
-webkit-animation-delay: -0.5s;
}
#keyframes flying {
100% {
background-position: -900px 0;
}
}
#-webkit-keyframes flying {
0% {
background-position: 0 0;
}
100% {
background-position: -900px 0;
}
}
#keyframes fly-across-1 {
0% {
transform: translateX(-10vw);
-webkit-transform: translateX(-10vw);
}
10% {
transform: translateY(-2vh) translateX(10vw);
-webkit-transform: translateY(-2vh) translateX(10vw);
}
20% {
transform: translateY(-4vh) translateX(30vw);
-webkit-transform: translateY(-4vh) translateX(30vw);
}
30% {
transform: translateY(-6vh) translateX(50vw);
-webkit-transform: translateY(-6vh) translateX(50vw);
}
40% {
transform: translateY(-5vh) translateX(70vw);
-webkit-transform: translateY(-5vh) translateX(70vw);
}
50% {
transform: translateY(-3vh) translateX(90vw);
-webkit-transform: translateY(-3vh) translateX(90vw);
}
60% {
transform: translateY(-2vh) translateX(110vw);
-webkit-transform: translateY(-2vh) translateX(110vw);
}
100% {
transform: translateY(0) translateX(110vw);
-webkit-transform: translateY(0) translateX(110vw);
}
}
#-webkit-keyframes fly-across-1 {
0% {
transform: translateX(-10vw);
-webkit-transform: translateX(-10vw);
}
10% {
transform: translateY(-2vh) translateX(10vw);
-webkit-transform: translateY(-2vh) translateX(10vw);
}
20% {
transform: translateY(-4vh) translateX(30vw);
-webkit-transform: translateY(-4vh) translateX(30vw);
}
30% {
transform: translateY(-6vh) translateX(50vw);
-webkit-transform: translateY(-6vh) translateX(50vw);
}
40% {
transform: translateY(-5vh) translateX(70vw);
-webkit-transform: translateY(-5vh) translateX(70vw);
}
50% {
transform: translateY(-3vh) translateX(90vw);
-webkit-transform: translateY(-3vh) translateX(90vw);
}
60% {
transform: translateY(-2vh) translateX(110vw);
-webkit-transform: translateY(-2vh) translateX(110vw);
}
100% {
transform: translateY(0) translateX(110vw);
-webkit-transform: translateY(0) translateX(110vw);
}
}
As you can see in the below animation, if you hover out then the animation stops abruptly. I would like to transition it to the final position down. Is there a way to do it while keeping keyframes?
.bounce{
width:100px;
height:100px;
background:red;
margin-top:100px;
}
.bounce:hover {
animation-name: bounce;
animation-duration: 1s;
animation-fill-mode: both;
animation-iteration-count: infinite;
}
#keyframes bounce {
0%, 100%, 20%, 50%, 80% {
-webkit-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0)
}
40% {
-webkit-transform: translateY(-30px);
-ms-transform: translateY(-30px);
transform: translateY(-30px)
}
60% {
-webkit-transform: translateY(-15px);
-ms-transform: translateY(-15px);
transform: translateY(-15px)
}
}
<div class="bounce"></div>
I am a bit confused on how keyframes work exactly in this demo. Whats confusing me is that 0% and 100% are not defined but 25% and 75% are. But at 0% the 25% keyframe is active. I thought it wouldn't be active until 25% through the animation until it hits the 75% keyframe. Also when does the 75% keyframe stop 100%? If you could explain exactly what is happening it would be appreciated. I hope this question is clear. Thanks.
#-webkit-keyframes pulse {
25% {
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
75% {
-webkit-transform: scale(0.8);
transform: scale(0.8);
}
}
#keyframes pulse {
25% {
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
75% {
-webkit-transform: scale(0.8);
-ms-transform: scale(0.8);
transform: scale(0.8);
}
}
.pulse {
display: inline-block;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
width: 50px;
height: 50px;
background-color: blue;
}
.pulse:hover {
-webkit-animation-name: pulse;
animation-name: pulse;
-webkit-animation-duration: 5s;
animation-duration: 5s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}
<div class="pulse">
</div>
hi if you don't need animation to happen then add
#keyframes <animation name>
{
0%,25%
{
animation here
}
75%,100%
{
animation here
}
}
what happens here is animation don't start up-to 25%, from 25% to 75% animation plays and stops after 75% until it reaches 100%
Is there a way to have two arrows "bouncing" in separate directions using CSS?
I have the following code on my site (domainmarket.io), which produces one bouncing arrow (which can be seen on the top left-hand corner), but I would like another arrow bouncing in another direction, but can't figure out how.
HTML
<div class="arrow bounce"></div>
<div class="topbarleft">
<a href="javascript:showhide('uniquename')">
<p><?php echo wp_kses_post( $ocin_topbar_text ); ?></p>
</a>
<div class="rightarrow bounceright"></div>
</div>
CSS
#-webkit-keyframes bounce{
0%, 20%, 50%, 80%, 100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
40% {
-webkit-transform: translateX(-30px);
transform: translateX(-30px);
}
60% {
-webkit-transform: translateX(-15px);
transform: translateX(-15px);
}
}
#-moz-keyframes bounce {
0%, 20%, 50%, 80%, 100% {
transform: translateX(0);
}
40% {
transform: translateX(-30px);
}
60% {
transform: translateX(-15px);
}
}
#keyframes bounce{
0%, 20%, 50%, 80%, 100% {
-ms-transform: translateX(0);
transform: translateX(0);
}
40% {
-ms-transform: translateX(-30px);
transform: translateX(-30px);
}
60% {
-ms-transform: translateX(-15px);
transform: translateX(-15px);
}
}
#-webkit-keyframes bounceright {
0%, 20%, 50%, 80%, 100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
40% {
-webkit-transform: translateX(30px)!important;
transform: translateX(30px)!important;
}
60% {
-webkit-transform: translateX(15px)!important;
transform: translateX(15px)!important;
}
}
#-moz-keyframes bounceright {
0%, 20%, 50%, 80%, 100% {
transform: translateX(0);
}
40% {
transform: translateX(30px)!important;
}
60% {
transform: translateX(15px)!important;
}
}
#keyframes bounceright {
0%, 20%, 50%, 80%, 100% {
-ms-transform: translateX(0);
transform: translateX(0);
}
40% {
-ms-transform: translateX(30px) !important;
transform: translateX(30px)!important;
}
60% {
-ms-transform: translateX(15px)!important;
transform: translateX(15px)!important;
}
}
.arrow {
margin-top:0px;
width: 24px;
height: 24px;
float: left;
margin-right: 10px;
background-image: url('http://domainmarket.io/wp-content/uploads/2016/04/arrow-1.png');
background-repeat: no-repeat;
}
.bounce {
-webkit-animation: bounce 2s infinite;
animation: bounce 2s infinite;
}
.bounceright {
-webkit-animation: bounce 2s infinite;
animation: bounce 2s infinite;
}
.rightarrow.bounceright {
background-image: url('http://domainmarket.io/wp-content/uploads/2016/04/arrowright.png');
background-repeat: no-repeat;
float: left;
width: 24px;
height: 24px;
display: inline-block;
}
As you can see in my CSS code, I've tried to change the #keyframes to bounceright to see if that would work, but it hasn't.
Got it figured out!
In the CSS file
.bounceright {
-webkit-animation: bounce 2s infinite;
animation: bounce 2s infinite;
}
SHOULD BE
.bounceright {
-webkit-animation: bounceright 2s infinite;
animation: bounceright 2s infinite;
}
Somehow, you adding !important to the bounceright keyframes disabled them. Remove it and it works.
Declarations in #keyframes that are marked with !important are ignored. See here: https://developer.mozilla.org/en/docs/Web/CSS/#keyframes#!important_in_a_keyframe
So here is the end result:
#keyframes bounceright {
0%, 20%, 50%, 80%, 100% {
-ms-transform: translateX(0);
transform: translateX(0);
}
40% {
-ms-transform: translateX(30px);
transform: translateX(30px)
}
60% {
-ms-transform: translateX(15px);
transform: translateX(15px);
}
}
Edit: also, as the author of the question explained, change "bounce" with "bounceright" in the .bounceright CSS rule:
.bounceright {
-webkit-animation: bounceright 2s infinite;
animation: bounceright 2s infinite;
}
However, I found a much simpler solution to all of this: instead of using another arrow and another class, just use the same. So instead of:
<div class="rightarrow bounceright"></div>
use
<div class="reverse"><div class="arrow bounce"></div></div>
with the CSS rule:
.reverse {
transform: rotate(180deg);
display:inline-block;
}
This way there is no duplication of the same code just to reverse the direction of the arrow.
I have this css :
.yellowText {
color: #FFFF00;
-ms-transform: rotate(-20deg); /* IE 9 */
-webkit-transform: rotate(-20deg); /* Chrome, Safari, Opera */
transform: rotate(-20deg);
}
.pulse {
-webkit-animation: text-anim;
animation: text-anim 1s;
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-timing-function: ease-in-out;
animation-timing-function: ease-in-out;
animation-iteration-count:infinite;
-webkit-animation-iteration-count:infinite;
}
#-webkit-keyframes text-anim {
0% { -webkit-transform: scale(1); }
50% { -webkit-transform: scale(1.1); }
100% { -webkit-transform: scale(1); }
}
#keyframes text-anim {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
Then, I apply it to a text :
<p class="yellowText pulse">Some text here</p>
But now, the text is well-animated, without being rotated by -20°... Any idea of what could be wrong ? I believe this is a problem with the transform property not working with the animation one. Also, what I tried was putting the transform inside the #keyframes text-anim, but what this does is just periodically rotating the text, having it perfectly right the rest of the time...
Thanks in advance for your help !
PS : forgive my bad English, I'm French :P
Your #keyframes are overriding you original transform property.
#-webkit-keyframes text-anim {
0% { -webkit-transform: scale(1 rotate(-20deg); }
50% { -webkit-transform: scale(1.1) rotate(-20deg); }
100% { -webkit-transform: scale(1) rotate(-20deg); }
}
#keyframes text-anim {
0% { transform: scale(1) rotate(-20deg); }
50% { transform: scale(1.1) rotate(-20deg); }
100% { transform: scale(1) rotate(-20deg); }
}