How to zoom in and out an image every second? - css

I'm looking for solution to my problem. I want to zoom in and out without stoping every second in a div with backgroung-image.
Something like this fruit in the game:
https://www.google.co.il/search?source=hp&ei=ghU7XfaEBai4gwfA6rrIDA&q=snake&oq=snaj&gs_l=psy-ab.1.0.35i305i39j0i10l9.776.1740..2868...0.0..0.192.754.0j5......0....1..gws-wiz.....0..35i39j0i131j0j0i67.KPZVLy3h8CU
I find the solution below but I use react so I need css/js solution and not jQuery one.
Zoom an image every one second jQuery

The solution is to use CSS "breathing" animation. An example how it works:
#breathing-button {
width: 270px;
padding: 20px;
margin: 50px auto;
border: 1px solid #d1d1d1;
-webkit-animation: breathing 7s ease-out infinite normal;
animation: breathing 7s ease-out infinite normal;
font-size: 24px;
background: #5885cb;
color: #fff;
-webkit-font-smoothing: antialiased;
border-radius: 3px;
text-align: center;
}
#-webkit-keyframes breathing {
0% {
-webkit-transform: scale(0.9);
transform: scale(0.9);
}
25% {
-webkit-transform: scale(1);
transform: scale(1);
}
60% {
-webkit-transform: scale(0.9);
transform: scale(0.9);
}
100% {
-webkit-transform: scale(0.9);
transform: scale(0.9);
}
}
#keyframes breathing {
0% {
-webkit-transform: scale(0.9);
-ms-transform: scale(0.9);
transform: scale(0.9);
}
25% {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
60% {
-webkit-transform: scale(0.9);
-ms-transform: scale(0.9);
transform: scale(0.9);
}
100% {
-webkit-transform: scale(0.9);
-ms-transform: scale(0.9);
transform: scale(0.9);
}
}
<div id="breathing-button">Breathing Button</div>

Related

How to animate the transform of an element so that it falls from above coming towards the screen?

I have an element that should come towards the user in front of the screen but also like falling from above.
I have tried transitioning from rotateX(-90deg) to rotateX(0) and from rotateX(360deg) to rotateX(270deg), but it does not look the way I want.
Also I do not what would be a good way to search for this on Google.
Sketch
Source code
body {
margin: 0 0;
}
.my-class-here {
width: 100%;
height: 100vh;
animation-name: header-anim;
animation-duration: 5s;
width: 200px;
height: 200px;
background-color: yellow;
text-align: center;
}
#keyframes header-anim {
0% {
transform: rotateX(360deg);
}
100% {
transform: rotateX(270deg);
}
}
<div class="my-class-here">
TEST
</div>
How can I achieve this?
Thank you!
You need to correct your transform-origin and add some perspective:
body {
margin: 0 0;
}
.my-class-here {
animation: header-anim 2s;
width: 200px;
height: 200px;
background-color: yellow;
text-align: center;
transform-origin:top; /* don't forget this */
}
#keyframes header-anim {
0% {
transform: perspective(200px) rotateX(270deg);
}
100% {
transform: perspective(200px) rotateX(360deg);
}
}
<div class="my-class-here">
TEST
</div>
I believe that this is what you're looking for.
#-webkit-keyframes slide-in-fwd-tr {
0% {
-webkit-transform: translateZ(-1400px) translateY(-800px) translateX(1000px);
transform: translateZ(-1400px) translateY(-800px) translateX(1000px);
opacity: 0;
}
100% {
-webkit-transform: translateZ(0) translateY(0) translateX(0);
transform: translateZ(0) translateY(0) translateX(0);
opacity: 1;
}
}
#keyframes slide-in-fwd-tr {
0% {
-webkit-transform: translateZ(-1400px) translateY(-800px) translateX(1000px);
transform: translateZ(-1400px) translateY(-800px) translateX(1000px);
opacity: 0;
}
100% {
-webkit-transform: translateZ(0) translateY(0) translateX(0);
transform: translateZ(0) translateY(0) translateX(0);
opacity: 1;
}
}

css3 rotate animation wont work

I have used css3 animate for small text to rotate but it wont rotate.
Jsfiddle
<h1 class="title">Coming Soon <small>btw learning</small></h1>
small {
animation:spin 4s linear infinite;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
20% { -webkit-transform: rotate(90deg); }
25% { -webkit-transform: rotate(90deg); }
45% { -webkit-transform: rotate(180deg); }
50% { -webkit-transform: rotate(180deg); }
70% { -webkit-transform: rotate(270deg); }
75% { -webkit-transform: rotate(270deg); }
100% { -webkit-transform: rotate(360deg); }
}
use display:inline-block;
<h1 class="title">Coming Soon <span class="animation">btw learning</span></h1>
.title
{
font-family: 'Cinzel Decorative', cursive;
text-align: center;
font-size: 100px;
margin-top: 25%;
}
.animation {
animation:spin 4s linear infinite;
display:inline-block;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
20% { -webkit-transform: rotate(90deg); }
25% { -webkit-transform: rotate(90deg); }
45% { -webkit-transform: rotate(180deg); }
50% { -webkit-transform: rotate(180deg); }
70% { -webkit-transform: rotate(270deg); }
75% { -webkit-transform: rotate(270deg); }
100% { -webkit-transform: rotate(360deg); }
}

Pause in infinitive CSS animation

I have created this arrow that bounces and I want to add a pause for like 2 seconds between the bounces. I found a couple of similar examples here but they didn't work for my arrow (changed the bouncing animation).
If i add the following I get a pause but only once:
-webkit-animation-delay: 2s; /* Safari 4.0 - 8.0 */
animation-delay: 2s;
Anyway, here is the code:
HTML:
<div class="btn-bottom"></div>
CSS:
.btn-bottom{
width: 48px;
height: 58px;
background: url("https://d30y9cdsu7xlg0.cloudfront.net/png/10897-200.png")
center center no-repeat;
background-size: 47px;
margin: auto;
top: 40px;
left: 0;
right: 0;
cursor: pointer;
-webkit-animation: bounce 2.5s infinite;
animation: bounce 2.5s infinite;
}
#-webkit-keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-webkit-transform: translateY(0);
}
40% {
-webkit-transform: translateY(-30px);
}
60% {
-webkit-transform: translateY(-15px);
}
}
#-moz-keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-moz-transform: translateY(0);
}
40% {
-moz-transform: translateY(-30px);
}
60% {
-moz-transform: translateY(-15px);
}
}
#keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-webkit-transform: translateY(0);
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-o-transform: translateY(0);
transform: translateY(0);
}
20%, 50%, 80%, 100% {
-webkit-transform: translateY(0);
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-o-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(-30px);
-moz-transform: translateY(-30px);
-ms-transform: translateY(-30px);
-o-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-webkit-transform: translateY(-15px);
-moz-transform: translateY(-15px);
-ms-transform: translateY(-15px);
-o-transform: translateY(-15px);
transform: translateY(-15px);
}
}
JSFIDDLE:
https://jsfiddle.net/92xmw541/
Easiest way is to make the duration of the animation longer (4s below) and use half of the animation time with the keyframes. The rest of the keyframes the object will be at rest.
.btn-bottom {
width: 48px;
height: 58px;
background: url("https://d30y9cdsu7xlg0.cloudfront.net/png/10897-200.png") center center no-repeat;
background-size: 47px;
margin: auto;
top: 40px;
left: 0;
right: 0;
cursor: pointer;
animation: bounce 4s infinite;
}
#keyframes bounce {
10%,
20%,
30%,
40%,
50% {
transform: translateY(0);
}
15% {
transform: translateY(-30px);
}
25% {
transform: translateY(-15px);
}
35% {
transform: translateY(-5px);
}
45% {
transform: translateY(-2px);
}
}
<div class="btn-bottom"></div>
Here is a pure Javascript solution I ended up with to achieve a delay between CSS animations (like animate.css).
function repeatAnimate(element, delay) {
delay = delay || 5000;
setTimeout(function () {
element.style.webkitAnimation = 'none';
setTimeout(function () {
element.style.webkitAnimation = '';
repeatAnimate(element, delay);
}, 10);
}, delay)
}
Usage:
$(function () {
var element = document.getElementsByClassName('btn-play')[0];
repeatAnimate(element, 2000);
});
In this case the animated and bounce classes are already present in the HTML markup.

Revert animation on exit

I am making a menu that should have animated "hamburger" icon inside. At first, I used transform and it looked nice, but I decided to add some fancier animation ;-)
They loook like this:
#keyframes animateFirstBar {
0% {
transform: translate(-50%, -200%);
}
50% {
transform: translate(-50%, 0);
}
100% {
transform: translateX(-50%) rotate(-45deg);
}
}
#keyframes animateSecoundBar {
0%, 50% {
transform: translate(-50%, 0);
}
51%, 100% {
transform: translate(-50%, 0) scaleX(.01);
}
}
#keyframes animateThirdBar {
0% {
transform: translate(-50%, 200%);
}
50% {
transform: translate(-50%, 0);
}
100% {
transform: translateX(-50%) rotate(45deg);
}
}
And they are used like this:
.main-menu {
$mainMenu: &;
position: fixed;
width: 300px;
height: 100%;
top: 0;
left: 0;
background: #ccc;
transform: translateX(-100%);
transition: $time transform ease-in;
&--active {
transform: none;
#{$mainMenu}__toggle {
transform: none;
background: rgba(0, 0, 0, 0);
}
#{$mainMenu}__toggle-line {
&:nth-of-type(1) {
animation: $time animateFirstBar forwards;
}
&:nth-of-type(2) {
animation: $time animateSecoundBar forwards;
}
&:nth-of-type(3) {
animation: $time animateThirdBar forwards;
}
}
}
&__toggle {
width: $width;
height: $width - 1;
position: absolute;
right: 0;
transform: translateX(100%);
top: 0;
background: yellow;
border: 0;
outline: 0;
transition: $time transform ease-in, $time background linear;
transform-origin: bottom right;
}
&__toggle-line {
width: 60%;
height: $lineHeight;
display: block;
background: black;
position: absolute;
left: 50%;
transition: $time transform ease-in;
top: (50% - ($lineHeight/2));
&:nth-of-type(1) {
animation: none;
transform: translate(-50%, -200%);
}
&:nth-of-type(2) {
animation: none;
transform: translate(-50%, 0);
}
&:nth-of-type(3) {
animation: none;
transform: translate(-50%, 200%);
}
}
}
You can see the example here: http://codepen.io/tomekbuszewski/pen/jrzKKR?editors=0100
My problem is, I don't know how to revert the animation on "exit" (on removing the --active modificator). I don't want to write another animations or add another class that will be removed over time with JS.
Previously I have already implemented this hamburger button with transition and transform and I think it is satisfied what you want to archive. I haven't done it with your approach using animation. But please take a look at this snippet to see the idea.
function toggleMenu(x) {
x.classList.toggle("change");
}
/*
Orginal article - https://github.com/trungk18/Animated-Navigation-Menu-Icons-with-CSS3
*/
/*Menu container*/
.content {
max-width: 40em;
margin: 1em auto;
}
.icon-container {
float: left;
position: relative;
cursor: pointer;
margin: 0 5em 5em;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.bar {
display: block;
width: 35px;
height: 5px;
background-color: #333;
margin: 6px auto;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border-radius: 3px;
}
.change {
/*Rotate first bar*/
/*Fade out the second bar-*/
/*Reduce width the second bar-*/
/*Rotate last bar*/
}
.change.icon-5 {
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
}
.change .bar-10 {
-webkit-transform: rotate(45deg) translate(8px, -3px) scaleX(0.7);
-moz-transform: rotate(45deg) translate(8px, -3px) scaleX(0.7);
-ms-transform: rotate(45deg) translate(8px, -3px) scaleX(0.7);
-o-transform: rotate(45deg) translate(8px, -3px) scaleX(0.7);
transform: rotate(45deg) translate(8px, -3px) scaleX(0.7);
}
.change .bar-12 {
-webkit-transform: rotate(-45deg) translate(8px, 3px) scaleX(0.7);
-moz-transform: rotate(-45deg) translate(8px, 3px) scaleX(0.7);
-ms-transform: rotate(-45deg) translate(8px, 3px) scaleX(0.7);
-o-transform: rotate(-45deg) translate(8px, 3px) scaleX(0.7);
transform: rotate(-45deg) translate(8px, 3px) scaleX(0.7);
}
<section class="content">
<div class="icon-container icon-5" onclick="toggleMenu(this)">
<span class="bar bar-10"></span>
<span class="bar bar-11"></span>
<span class="bar bar-12"></span>
</div>
</section>
<!--Full pen: http://codepen.io/trungk18/pen/jrrXjz-->
I've managed to solve the problem. I had to add another class, trigger it with JS and write another set of animations that flowed in reverse.
Animations:
#keyframes animateFirstBar {
0% { transform: translate(-50%, $spacing * -100%); }
60% { transform: translate(-50%, 0); }
100% { transform: translateX(-50%) rotate(-#{$rotation}deg); }
}
#keyframes revertFirstBar {
100% { transform: translate(-50%, $spacing * -100%); }
60% { transform: translate(-50%, 0); }
0% { transform: translateX(-50%) rotate(-#{$rotation}deg); }
}
#keyframes animateSecoundBar {
0%, 60% { transform: translate(-50%, 0); }
61%, 100% { transform: translate(-50%, 0) scaleX(.01); }
}
#keyframes revertSecoundBar {
0%, 60% { transform: translate(-50%, 0) scaleX(.01); }
61%, 100% { transform: translate(-50%, 0); }
}
#keyframes animateThirdBar {
0% { transform: translate(-50%, $spacing * 100%); }
60% { transform: translate(-50%, 0); }
100% { transform: translateX(-50%) rotate(#{$rotation}deg); }
}
#keyframes revertThirdBar {
0% { transform: translateX(-50%) rotate(#{$rotation}deg); }
60% { transform: translate(-50%, 0); }
100% { transform: translate(-50%, $spacing * 100%); }
}
revert*Bar are going with one class, animate*Bar with another.

CSS animation not working when directly copied from demo

I am trying to use a CSS (buzz out) animation as can be seen here.
Works perfectly in the demo, I have copied the relevant CSS and can't get it to work on a website so I even made a simple jsFiddle and it still doesn't work.
Please can someone point out what I am evidently missing as this is all the CSS seems to contain and I am a bit baffled to how it is working with the same style declaration on the demo but not in the jsFiddle.
Code snippet included below as well as at jsFiddle.
[class^="hvr-"] {
/* display: inline-block; */
/* vertical-align: middle; */
margin: .4em;
padding: 1em;
cursor: pointer;
background: #e1e1e1;
text-decoration: none;
color: #666;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
.hvr-buzz-out {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
}
.hvr-buzz-out:hover, .hvr-buzz-out:focus, .hvr-buzz-out:active {
-webkit-animation-name: hvr-buzz-out;
animation-name: hvr-buzz-out;
-webkit-animation-duration: 0.75s;
animation-duration: 0.75s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-iteration-count: 1;
animation-iteration-count: 1;
}
Buzz Out
You also need the #keyframes that define the animation:
#-webkit-keyframes hvr-buzz-out {
10% {
-webkit-transform: translateX(3px) rotate(2deg);
transform: translateX(3px) rotate(2deg);
}
20% {
-webkit-transform: translateX(-3px) rotate(-2deg);
transform: translateX(-3px) rotate(-2deg);
}
30% {
-webkit-transform: translateX(3px) rotate(2deg);
transform: translateX(3px) rotate(2deg);
}
40% {
-webkit-transform: translateX(-3px) rotate(-2deg);
transform: translateX(-3px) rotate(-2deg);
}
50% {
-webkit-transform: translateX(2px) rotate(1deg);
transform: translateX(2px) rotate(1deg);
}
60% {
-webkit-transform: translateX(-2px) rotate(-1deg);
transform: translateX(-2px) rotate(-1deg);
}
70% {
-webkit-transform: translateX(2px) rotate(1deg);
transform: translateX(2px) rotate(1deg);
}
80% {
-webkit-transform: translateX(-2px) rotate(-1deg);
transform: translateX(-2px) rotate(-1deg);
}
90% {
-webkit-transform: translateX(1px) rotate(0);
transform: translateX(1px) rotate(0);
}
100% {
-webkit-transform: translateX(-1px) rotate(0);
transform: translateX(-1px) rotate(0);
}
}
#keyframes hvr-buzz-out {
10% {
-webkit-transform: translateX(3px) rotate(2deg);
transform: translateX(3px) rotate(2deg);
}
20% {
-webkit-transform: translateX(-3px) rotate(-2deg);
transform: translateX(-3px) rotate(-2deg);
}
30% {
-webkit-transform: translateX(3px) rotate(2deg);
transform: translateX(3px) rotate(2deg);
}
40% {
-webkit-transform: translateX(-3px) rotate(-2deg);
transform: translateX(-3px) rotate(-2deg);
}
50% {
-webkit-transform: translateX(2px) rotate(1deg);
transform: translateX(2px) rotate(1deg);
}
60% {
-webkit-transform: translateX(-2px) rotate(-1deg);
transform: translateX(-2px) rotate(-1deg);
}
70% {
-webkit-transform: translateX(2px) rotate(1deg);
transform: translateX(2px) rotate(1deg);
}
80% {
-webkit-transform: translateX(-2px) rotate(-1deg);
transform: translateX(-2px) rotate(-1deg);
}
90% {
-webkit-transform: translateX(1px) rotate(0);
transform: translateX(1px) rotate(0);
}
100% {
-webkit-transform: translateX(-1px) rotate(0);
transform: translateX(-1px) rotate(0);
}
}
[class^="hvr-"] {
/* display: inline-block; */
/* vertical-align: middle; */
margin: .4em;
padding: 1em;
cursor: pointer;
background: #e1e1e1;
text-decoration: none;
color: #666;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
.hvr-buzz-out {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
}
.hvr-buzz-out:hover, .hvr-buzz-out:focus, .hvr-buzz-out:active {
-webkit-animation-name: hvr-buzz-out;
animation-name: hvr-buzz-out;
-webkit-animation-duration: 0.75s;
animation-duration: 0.75s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-iteration-count: 1;
animation-iteration-count: 1;
}
Buzz Out
They were also in the CSS file above the code you already had.

Resources