How do you reverse css keyframe animation in webkit? - html

I have a control that I want to transition between two locations following a keyframe animation. Is there a way to use the same keyframe but in reverse? Also, is there a way to stop the animation, halfway and reverse it to the beginning?
Here is what I have now (and I want to combine the two keyframes:
#-webkit-keyframes explode {
0% {
-webkit-transform: scale(1.0) rotate(0deg) translate(0px, 0px);
}
33% {
-webkit-transform: scale(2.0) translate(100px, -150px);
}
67% {
-webkit-transform: scale(2.0) translate(200px, -250px);
}
100% {
-webkit-transform: scale(1.0) translate(-15px, -15px);
}
}
#-webkit-keyframes explodeBack {
0% {
-webkit-transform: scale(1.0) translate(-15px, -15px);
}
67% {
-webkit-transform: scale(2.0) translate(100px, -150px);
}
100% {
-webkit-transform: scale(1.0) rotate(0deg) translate(0px, 0px);
}
}
.leftArrowAnimateForward{
-webkit-animation-name: explode;
-webkit-animation-duration: 3s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction:normal; /* Safari and Chrome */
-webkit-transform: scale(1.0) translate(-15px, -15px);
}
.leftArrowAnimateBackward{
-webkit-animation-name: explodeBack;
-webkit-animation-duration: 3s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction:alternate;
-webkit-transform: scale(1.0) translate(0px, 0px);
}

It's hard to see what your trying to do without visually seeing what you have so far, but checkout animation-fill-mode.
This will allow your animation to stop on the last keyframe when set to forward, where at the moment I believe the keyframes go back to 0 when they are finished.
Have a play and let us know if your successful.

You can do the first thing you want to do if you combine animation-iteration-count: 2, with an animation-direction: alternate, and a animation-delay that is negative the length of your animation, you will get an animation to play in reverse exactly once. (It basically skips ahead to the reverse direction animation and starts playing there.)
You can't do the second thing you want to do with pure CSS animation, unless you define a second set of keyframes and toggle between the classes with JS (or hover or whatever)

I had the same problem, and use SCSS to generate two version of keyframe: normal and reverse.
https://github.com/lichunbin814/scss-utils#with-reverse-version
/* mixin */
#mixin keyframe-reverse( $name, $value) {
#keyframes #{$name}-rev {
#each $position,
$change in $value {
#{ 100 -$position}% {
#each $prop,
$val in $change {
#{$prop}: #{$val};
}
}
}
}
}
#mixin keyframe-normal( $name, $value) {
#keyframes #{$name} {
#each $position,
$change in $value {
#{$position}% {
#each $prop,
$val in $change {
#{$prop}: #{$val};
}
}
}
}
}
#mixin keyframe-gen( $name, $value, $genReverse) {
#include keyframe-normal( $name: $name, $value: $value);
#if ($genReverse) {
#include keyframe-reverse( $name: $name, $value: $value)
}
}
/* use */
#include keyframe-gen(
$name : "fadeIn" ,
$value : (
0: (
transform: scale(1),
opacity: 1
),
100: (
transform: scale(0),
opacity: 0
),
) ,
$genReverse : true
);
.menu {
animation-name: fadeIn-rev;
&.active {
animation-name: fadeIn;
}
}
// output css
/*
#keyframes fadeIn {
0% {
transform: scale(1);
opacity: 1;
}
100% {
transform: scale(0);
opacity: 0;
}
}
#keyframes fadeIn-rev {
100% {
transform: scale(1);
opacity: 1;
}
0% {
transform: scale(0);
opacity: 0;
}
}
*/

Related

appearing blank space below footer in WordPress website after adding CSS code ( transform: rotate(-6deg)} )

On a WordPress website, in (section -> column -> inner section -> column -> heading) added marquee text by adding below HTML code in (section -> column)
& also added CSS Class in an inner section
sliding-text
& duplicate the inner section
in order to reverse the flow of the second line, I added CSS Class in a duplicate inner section
sliding-text reverse
But I also want to tilt the text a little too (-6deg) which only works for the first line so I also added
selector{ transform: rotate(-6deg)}
which leads to blank space below the footer and when I remove the (transform: rotate(-6deg)}) code blank space is also removed
<style>
body{
--speed: 15s;
}
.sliding-text .elementor-widget-wrap{
transform: rotate(-6deg);
}
.sliding-text .elementor-widget-wrap{
display: block !important;
}
.sliding-text .elementor-widget{
overflow: hidden;
width: 10000vw !important;
max-width: 10000vw !important;
}
.sliding-text .sliding .elementor-widget-container{
-webkit-animation: sliding var(--speed) linear infinite;
-moz-animation: sliding var(--speed) linear infinite;
-o-animation: sliding var(--speed) linear infinite;
animation: sliding var(--speed) linear infinite;
}
.sliding-text .elementor-widget-container{
float: left;
}
.sliding-text.reverse .elementor-widget-wrap{
transform: rotate(180deg);
}
.sliding-text.reverse .sliding .elementor-heading-title{
transform: scale(-1, -1);
}
#keyframe sliding{
0%{ transform: translateX(0); }
100%{ transform: translateX(-100%); }
}
#-webkit-keyframes sliding {
0%{ transform: translateX(0); }
100%{ transform: translateX(-100%); }
}
#-moz-keyframes sliding {
0%{ transform: translateX(0); }
100%{ transform: translateX(-100%); }
}
#-o-keyframes sliding {
0%{ transform: translateX(0); }
100%{ transform: translateX(-100%); }
}
#keyframes sliding {
0%{ transform: translateX(0); }
100%{ transform: translateX(-100%); }
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
var $ = jQuery
$(document).ready(function(){
var h = []
$('.sliding-text').each(function(){
h.push($(this).find('.elementor-widget').clone().html())
})
function init(){
$('.sliding-text').each(function(i){
var $this = $(this)
$this.find('.elementor-widget').removeClass('sliding')
var amount = Math.ceil($(window).width()/$(this).find('.elementor-widget-container').outerWidth(true)) + 1
$this.find('.elementor-widget').empty().addClass('sliding')
$this.find('.elementor-widget').html(h[i].repeat(amount))
})
}
init()
$(window).on('load resize', init)
})
</script>
Update:
Add the following CSS:
.elementor.elementor-1535 {
overflow: hidden;
}
it should fix the issue.

Trying to play a animation on scrolling down and rewind on scrolling up

I am trying to play an MP4 video while scrolling down and then rewind it while scrolling up.
I currently have the video (of an animation) working with HTML CSS and JS.
Any help would be appreciated thank you.
I have made a small example to display with an image. like when you scroll down some animation will be shown and once you scroll back to up animation will be revert.
CSS STYLE:
.classname {
-webkit-animation-name: cssAnimation;
-webkit-animation-duration: 3s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: backwards;
}
.classname1 {
-webkit-animation-name: cssAnimation1;
-webkit-animation-duration: 3s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: forwards;
}
#-webkit-keyframes cssAnimation1 {
from {
-webkit-transform: rotate(1deg) scale(1) skew(0deg) translate(20px);
}
to {
-webkit-transform: rotate(1deg) scale(1) skew(0deg) translate(20px);
}
}
#-webkit-keyframes cssAnimation {
from {
-webkit-transform: rotate(0deg) scale(2) skew(0deg) translate(100px);
}
to {
-webkit-transform: rotate(0deg) scale(2) skew(0deg) translate(100px);
}
}
**JAVASCRIPT PART**
var lastScrollTop = 0;
document.addEventListener("scroll", function(){
var value = window.pageYOffset || document.documentElement.scrollTop;
if (value > lastScrollTop){
scrollDownAnnimation();
} else {
scrollUpAnnimation();
}
lastScrollTop = value <= 0 ? 0 : st;
});
function scrollDownAnnimation() {
document.getElementById('img').className = 'classname';
}
function scrollUpAnnimation() {
document.getElementById('img').className = 'classname1';
}
**HTML PART: Please make sure you have added page content so that scroll can come on page**
<div>
<img id="img" src="https://i.stack.imgur.com/vghKS.png" width="328" height="328" />
</div>
For Demo: DEMO
Hope this help, Thanks!

CSS: Infinitely looping animation doesn't interpolate between the first and last keyframes

I'm fairly certain I'm noticing this right and I can't seem to find a proper solution anywhere. I have a CSS animation that's meant to loop infinitely, it already works but has a problem.
// CSS
#keyframes myanim {
0% { transform: translate(0, 0) rotate(0deg) skewX(0deg); }
25% { transform: translate(5px, 5px) rotate(1deg) skewX(1deg); }
50% { transform: translate(0, 0) rotate(0eg) skewX(0deg); }
75% { transform: translate(-5px, -5px) rotate(-1deg) skewX(-1deg); }
100% { transform: translate(0, 0) rotate(0deg) skewX(0deg); }
}
// JS
element.style.animation = "myanim " + mytimer + "s infinite";
Keyframe interpolation doesn't seem to work around the seams. Between points 0% and 100% there's no interpolation: When the animation just started or is approaching the end each iteration, it slows down / sets into place / speeds up instead of maintaining its constant rhythm like between the other keyframes. It it possible to tell the browser to interpret all keyframes in a circular manner for the loop to work as intended?
# MirceaKitsune is right you need to use the linear animation property.
I tried out the animation and it works, here is the fiddle:
.animated-heading {
animation: linear myanim 2s infinite;
}
#keyframes myanim {
0% {
transform: translate(0, 0) rotate(0deg) skewX(0deg);
}
12.5% {
transform: translate(2.5px, 2.5px) rotate(0.5deg) skewX(0.5deg);
}
25% {
transform: translate(5px, 5px) rotate(1deg) skewX(1deg);
}
37.5% {
transform: translate(2.5px, 2.5px) rotate(0.5deg) skewX(0.5deg);
}
50% {
transform: translate(0, 0) rotate(0eg) skewX(0deg);
}
62.5% {
transform: translate(-2.5px, -2.5px) rotate(-0.5deg) skewX(-0.5deg);
}
75% {
transform: translate(-5px, -5px) rotate(-1deg) skewX(-1deg);
}
87.5% {
transform: translate(-2.5px, -2.5px) rotate(-0.5deg) skewX(-0.5deg);
}
100% {
transform: translate(0, 0) rotate(0deg) skewX(0deg);
}
}
<h1 class="animated-heading">animated-heading</h1>

Combine css animations on an image element [duplicate]

This question already has answers here:
How to apply multiple transforms in CSS?
(9 answers)
Closed 2 years ago.
I'm just starting to learn some css (I was working before only in PHP + JS) and I wanted to make an animation of my image text. It should Slide bottom and Zoom in at the same time. I managed to do both but separately. I have no idea how to combine them...
Here is an example of what I have achieved:
https://jsfiddle.net/ta7208Lq/20/
// HTML
<div class="row">
<img class="zoom" src="https://cdn.shopify.com/s/files/1/0496/1029/files/Freesample.svg?5153" />
<img class="slide-bottom" src="https://cdn.shopify.com/s/files/1/0496/1029/files/Freesample.svg?5153" />
</div>
// CSS
.slide-bottom {
-webkit-animation: slide-bottom 1s;
animation: slide-bottom 1s;
}
.zoom {
-webkit-animation: zoom-in 1s;
animation: zoom-in 1s;
}
/* ----------------------------------------------
* Generated by Animista on 2020-11-7 16:22:35
* Licensed under FreeBSD License.
* See http://animista.net/license for more info.
* w: http://animista.net, t: #cssanimista
* ---------------------------------------------- */
/**
* ----------------------------------------
* animation slide-bottom
* ----------------------------------------
*/
#-webkit-keyframes slide-bottom {
0% {
-webkit-transform: translateY(0);
transform: translateY(0);
}
100% {
-webkit-transform: translateY(150px);
transform: translateY(150px);
}
}
#keyframes slide-bottom {
0% {
-webkit-transform: translateY(0);
transform: translateY(0);
}
100% {
-webkit-transform: translateY(150px);
transform: translateY(150px);
}
}
/**
* ----------------------------------------
* animation zoom-in
* ----------------------------------------
*/
#-webkit-keyframes zoom-in {
0% {
-webkit-transform: scale(0.5);
transform: scale(0.5);
}
100% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}
#keyframes zoom-in {
0% {
-webkit-transform: scale(0.5);
transform: scale(0.5);
}
100% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}
.row {
float: left;
}
img {
display: inline-block;
}
The idea is of course to put it on one image, I have just added two to illustrate the problem.
If you want to perform multiple animation at the same time, you can add additional transitions as transform: translateY(0) scale(0.2) .., And then update in keyframes as well. Here is the updated code

To let the animation complete on mouse leave

I have written keyframe animation on hover.
#keyframes juggle {
0%{ transform: skew(15deg, 15deg) translate(0,10px);}
50%{ transform: skew(-15deg, -15deg) translate(0,-10px);}
100%{ transform: skew(15deg, 15deg) translate(0,0);}
}
span:hover{ animation: juggle 1s; }
The animation works fine but on mouse leave, it stops abruptly.
The expectation is to complete the animation even on mouse leave.
Is it possible to do it without jquery.
Hope this works
let section = document.getElementById('homeSection');
let elmnt = section.getElementsByClassName('classname');
for (let i = 0; i < elmnt.length; i++) {
elmnt[i].addEventListener('mouseenter', function () {
elmnt[i].classList.add('Juggle');
setTimeout(function(){
elmnt[i].classList.remove('Juggle')
},400)
})
}
I believe this is something you trying to do
span {
animation-name: juggle-out;
animation-duration: 1s;
animation-repeat-count: 1;
animation-fill-mode: forwards;
}
span:hover{
animation-name: juggle-in;
}
#keyframes juggle-in {
0%{ transform: skew(15deg, 15deg) translate(0,10px);}
50%{ transform: skew(-15deg, -15deg) translate(0,-10px);}
100%{ transform: skew(15deg, 15deg) translate(0,0);}
}
#keyframes juggle-out {
0%{ transform: skew(15deg, 15deg) translate(0,10px);}
50%{ transform: skew(-15deg, -15deg) translate(0,-10px);}
100%{ transform: skew(0deg, 0deg) translate(0,0);}
}
you should use 2 animations for hover in and hover out
actually there is no hover in and hover out in CSS
It's just a state but the animation-fill-mode plays an important role
The support is not very good though ;)
I recommend adding class instead of this
Use the onmouseover function to add a class which contains the animation and manually remove the class using settimeout function.