Make Button Bounce with CSS3 - html

I am trying to make this button bounce with CSS3
.order {
position: absolute;
top: 50px;
left: 50px;
width: 75px;
line-height: 75px;
text-align:center;
opacity: 1;
background: green;
color:#fff;
border-radius:50%;
}
<div class="order">Order</div>
I would like it to bounce towards the screen (on the Z axis) up and down.

You can use a keyframe animation to animate the scale ratio and make your button bounce:
.order {
position: absolute;
top: 50px;
left: 50px;
width: 75px;
line-height: 75px;
text-align:center;
opacity: 1;
background: green;
color:#fff;
border-radius:50%;
animation: bounce .3s infinite alternate;
}
#keyframes bounce {
to { transform: scale(1.2); }
}
<div class="order">Order</div>
Iteration count:
If you want to stop the animation after a number of "bounces", you can use animation-iteration-count (use an even number of iterations otherwise the animation will snap on the last iteration) :
.order {
position: absolute;
top: 50px;
left: 50px;
width: 75px;
line-height: 75px;
text-align:center;
opacity: 1;
background: green;
color:#fff;
border-radius:50%;
animation: bounce .3s infinite alternate;
animation-iteration-count: 8;
}
#keyframes bounce {
to { transform: scale(1.2); }
}
<div class="order">Order</div>

try this css
.order {
background:url("http://onestudio.id-staging.com/_BUILD/Dominos/BANNERS/C3%20Digital%20Midweek%20Rescue/Wide%20Skyscraper/images/order.png");
background-size: cover;
position: absolute;
top:50px;
left:50px;
width: 75px;
height: 75px;
z-index:1;
opacity:1;
}
#keyframes fade {
from { top:40px;
left:40px;
width: 100px;
height: 100px; }
50% { top:50px;
left:50px;
width: 75px;
height: 75px; }
to { top:40px;
left:40px;
width: 100px;
height: 100px; }
}
#-webkit-keyframes fade {
from { top:40px;
left:40px;
width: 100px;
height: 100px; }
50% { top:50px;
left:50px;
width: 75px;
height: 75px; }
to { top:40px;
left:40px;
width: 100px;
height: 100px; }
}
.blink {
animation:fade 1000ms infinite;
-webkit-animation:fade 1000ms infinite;
}
try this html
<div class="order blink"></div>

The answer posted by web-tiki, would be the best one to use, still I have a different approach becoz you have already used position:absolute.
See this FIDDLE
you need to animate height and width for button using keyframe.
.order {
background: url("http://onestudio.id-staging.com/_BUILD/Dominos/BANNERS/C3%20Digital%20Midweek%20Rescue/Wide%20Skyscraper/images/order.png") no-repeat;
position: absolute;
background-size: cover;
top: 50px;
left: 50px;
width: 75px;
height: 75px;
z-index: 1;
opacity: 1;
-webkit-animation: mymove 1s infinite;
/* Chrome, Safari, Opera */
animation: mymove 1s infinite;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes mymove {
0% {
height: 75px;
width: 75px;
}
50% {
height: 100px;
width: 100px;
}
100% {
height: 75px;
width: 75px;
}
}
/* Standard syntax */
#keyframes mymove {
0% {
height: 75px;
width: 75px;
}
50% {
height: 100px;
width: 100px;
}
100% {
height: 75px;
width: 75px;
}
}
<div class="order"></div>
Edit:
To add further, you can also animate left and top to 38px both so the
button doesn't look like deviating from original position see this
Fiddle
.order {
background: url("http://onestudio.id-staging.com/_BUILD/Dominos/BANNERS/C3%20Digital%20Midweek%20Rescue/Wide%20Skyscraper/images/order.png") no-repeat;
position: absolute;
background-size: cover;
top: 50px;
left: 50px;
width: 75px;
height: 75px;
z-index: 1;
opacity: 1;
-webkit-animation: mymove 1s infinite;
/* Chrome, Safari, Opera */
animation: mymove 0.5s 2;
}
/* Standard syntax */
#keyframes mymove {
0% {
height: 75px;
width: 75px;
left: 50px;
top: 50px;
}
50% {
height: 100px;
width: 100px;
left: 38px;
top: 38px;
}
100% {
height: 75px;
width: 75px;
left: 50px;
top: 50px;
}
}
<div class="order"></div>

You can animate(bounce) like following:
CSS:
.order {
background:url("http://onestudio.id-staging.com/_BUILD/Dominos/BANNERS/C3%20Digital%20Midweek%20Rescue/Wide%20Skyscraper/images/order.png");
position: absolute;
top:50px;
left:50px;
width: 75px;
height: 75px;
z-index:1;
opacity:1;
animation: myfirst 2s infinite;
-webkit-animation: myfirst 2s infinite;
}
#-webkit-#keyframes myfirst {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
#keyframes myfirst {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
Check Fiddle

Related

Cannot animate width of an element using CSS Animation

I am using animations in CSS but it is not working. If I check in the inspect menu it is showing invalid syntax even though the syntax is normal. I have other two animations but they are working fine.
Only a particular animation in which I am trying to adjust the width isn't working.
* {
margin: 0;
padding: 0;
}
body {
overflow: hidden;
}
.bg-div {
background: url(imgs/sky.png);
height: 100vh;
background-size: 79% 792px;
background-position-y: -332px;
width: 900vw;
}
.sea-div {
background: url(imgs/sea.jpg);
height: 37vh;
position: absolute;
bottom: 0;
width: 900vw;
background-size: 10% 403px;
}
.bg-ani-class {
animation: seaMove linear infinite 3s;
background-repeat: repeat-x;
}
.sea-ani-class {
animation: seaMove linear infinite 6s;
background-repeat: repeat-x;
}
.obst-ani-class {
animation: obstMove linear 5s;
}
.mountain-div {
position: absolute;
top: 10vh;
/* width: 18vh; */
/* height: 20vh; */
left: 108vw;
}
.mountain-div img {
width: 148vh;
}
.hanuman-div {
position: absolute;
top: 28vh;
left: 3vw;
}
.hanuman-div img {
width: 20vw;
}
#gada {
position: absolute;
left: 0;
/* top: 56px; */
transition: 0.1s ease all;
}
.gada-rot {
left: 8vw !important;
transform: rotate(180deg);
top: -22px !important;
}
.laser {
position: absolute;
transform: rotateZ(189deg);
/* top: -14vh; */
left: 282px;
/* width: 45vw !important; */
width: 0% !important;
/* transition: 0.4s ease-out; */
animation: laserAnimation infinite 3s;
}
.dragon-1-div {}
.dragon-2-div {}
/* Animations */
/* These 2 Animations are working */
#keyframes seaMove {
100% {
transform: translateX(-500vw);
}
}
#keyframes obstMove {
0% {
left: 108vw;
}
100% {
left: -100vw;
}
}
/* This animation isn't working */
#keyframes laserAnimation {
from {
width: 0 !important;
}
to {
width: 45vw !important;
}
}
<div class="bg-div bg-ani-class"></div>
<div class="sea-div sea-ani-class"></div>
<div class="hanuman-div">
<img src="imgs/hanuman.png" alt="">
<img src="imgs/gada.png" alt="" id="gada">
<img src="imgs/laserbeam.png" alt="" class="laser">
</div>
<div class="mountain-div">
<img src="imgs/mountain.png" alt="">
</div>
<div class="dragon-1-div"></div>
<div class="dragon-2-div"></div>
It's generally not a good idea to animate width and height. Always try to use composite animations e.g. opacity, transforms. To achieve width animation use scale transform.
Here is a laser show for you:
body {
overflow: hidden;
}
.laser {
position: absolute;
left: 0;
top: 50%;
height: 10px;
width: 100%;
background: #d7272b;
animation: laserAnimation 2s ease-out infinite;
}
.greenLaser {
position: absolute;
left: 0;
top: 0;
height: 10px;
width: 100%;
background: #0063d5;
animation: laserAnimation 2s ease-out infinite;
}
.blueLaser {
position: absolute;
bottom: 0;
left: 0;
height: 10px;
width: 100%;
background: #00d53b;
animation: laserAnimation 2s ease-out infinite;
}
#keyframes laserAnimation {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
<div class="laser">
</div>
<div class="greenLaser">
</div>
<div class="blueLaser">
</div>

How to change animation direction inside div

I have created a div with animation direction to the right side but I want that the image inside will stay stright and will not move.
The problem is that the image is getting the direction of the main div.
#loader {
/* Uncomment this to make it run! */
/*
animation: loader 5s linear infinite;
*/
position: absolute;
top: calc(50% - 20px);
left: calc(50% - 20px);
}
#keyframes loader {
0% {
left: -100px
}
100% {
left: 110%;
}
}
#box {
width: 50px;
height: 50px;
background: #1d80e1;
animation: animate .5s linear infinite;
position: absolute;
top: 0;
left: 0;
border-radius: 5px;
width: 80px;
height: 80px;
background-size: 50px;
background-position: center;
background-image: url("https://picsum.photos/id/10/80/80");
background-repeat: no-repeat;
}
#keyframes animate {
17% {
border-bottom-right-radius: 3px;
}
25% {
transform: translateY(9px) rotate(22.5deg);
}
50% {
transform: translateY(18px) scale(1, .9) rotate(45deg);
border-bottom-right-radius: 40px;
}
75% {
transform: translateY(9px) rotate(67.5deg);
}
100% {
transform: translateY(0) rotate(90deg);
}
}
#shadow {
width: 50px;
height: 5px;
background: #000;
opacity: 0.1;
position: absolute;
top: 59px;
left: 0;
border-radius: 50%;
animation: shadow .5s linear infinite;
}
#keyframes shadow {
50% {
transform: scale(1.2, 1);
}
}
body {
background: #e4e4e4;
overflow: hidden;
}
h4 {
position: absolute;
bottom: 20px;
left: 20px;
margin: 0;
font-weight: 200;
opacity: .5;
font-family: sans-serif;
color: #fff;
}
<div id="loader">
<div id="shadow"></div>
<div id="box"></div>
</div>
In this case, I've used reverse flow. you can customize animate2. animate2 .5s infinite linear reverse;
#loader {
/* Uncomment this to make it run! */
/*
animation: loader 5s linear infinite;
*/
position: absolute;
top: calc(50% - 20px);
left: calc(50% - 20px);
}
#keyframes loader {
0% {
left: -100px
}
100% {
left: 110%;
}
}
#box:after {
content: '';
position: absolute;
top: 0;
left: 0;
border-radius: 5px;
width: 80px;
height: 80px;
background-size: 50px;
background-position: center;
background-image: url("https://picsum.photos/id/10/80/80");
background-repeat: no-repeat;
animation: animate2 .5s infinite linear reverse;
}
#box {
animation: animate .5s infinite linear;
width: 50px;
height: 50px;
background: #1d80e1;
position: absolute;
top: 0;
left: 0;
border-radius: 5px;
width: 80px;
height: 80px;
}
#keyframes animate {
17% {
border-bottom-right-radius: 3px;
}
25% {
transform: translateY(9px) rotate(22.5deg);
}
50% {
transform: translateY(18px) scale(1, .9) rotate(45deg);
border-bottom-right-radius: 40px;
}
75% {
transform: translateY(9px) rotate(67.5deg);
}
100% {
transform: translateY(0) rotate(90deg);
}
}
#keyframes animate2 {
17% {
}
25% {
transform:rotate(22.5deg);
}
50% {
transform:rotate(45deg);
}
75% {
transform:rotate(67.5deg);
}
100% {
transform:rotate(90deg);
}
}
#shadow {
width: 50px;
height: 5px;
background: #000;
opacity: 0.1;
position: absolute;
top: 59px;
left: 0;
border-radius: 50%;
animation: shadow .5s linear infinite;
}
#keyframes shadow {
50% {
transform: scale(1.2, 1);
}
}
body {
background: #e4e4e4;
overflow: hidden;
}
h4 {
position: absolute;
bottom: 20px;
left: 20px;
margin: 0;
font-weight: 200;
opacity: .5;
font-family: sans-serif;
color: #fff;
}
<div id="loader">
<div id="shadow"></div>
<div id="box"></div>
</div>

why my second image is not moving or animating

i am trying to animate 2 images:
1.from bottom left to top right.
other from bottom right to top left.
image 1 is moving while the other is not...
1 image is moving (the image from bottom left to top right), the other is still not moving
when i run the code of still image in saprate html filr it runs fine...
<style>
html
{
height:100%
}
body
{
height: 100%;
width:100%;
margin: 0;
background-repeat: no-repeat;
/* background-attachment: fixed;*/
background-image: radial-gradient(black,white);
}
div.move_to_right
{
width: auto;
height: auto;
position: absolute;
left:200px;
/*background-color: black;*/
/* background-image: url('/f16.png');*/
}
.move_to_right{
position: absolute;
left:200px;
}
#move_to_right
{
width: 150px;
height: 150px;
position: relative;
-webkit-animation-name: example; /* Safari 4.0 - 8.0 */
-webkit-animation-duration: 10s; /* Safari 4.0 - 8.0 */
animation-name: example;
animation-duration: 3s;
animation-iteration-count:infinite;
}
.ptag
{
color:white;
}
/* Safari 4.0 - 8.0 */
/* Standard syntax */
#keyframes example {
0%{
opacity: 0.5;
transform: translate(-200px,150px);
}
100%{
opacity: 1;
transform: translate(0px,0px);
}
div.move_to_left
{
width: auto;
height: auto;
position: absolute;
left:200px;
/*background-color: black;*/
/* background-image: url('/f16.png');*/
}
.move_to_left{
position: absolute;
right:200px;
}
#move_to_left
{
width: 150px;
height: 150px;
position: relative;
-webkit-animation-name: example; /* Safari 4.0 - 8.0 */
-webkit-animation-duration: 10s; /* Safari 4.0 - 8.0 */
animation-name: example;
animation-duration: 3s;
animation-iteration-count:infinite;
}
.ptag
{
color:white;
}
/* Safari 4.0 - 8.0 */
/* Standard syntax */
#keyframes example {
0%{
opacity: 0.5;
transform: translate(200px,150px);
}
100%{
opacity: 1;
transform: translate(0px,0px);
}
</style>
<html><body>
<div class="move_to_right">
<!--<img id="move" src="https://pngimage.net/wp-content/uploads/2018/05/f16-png-6.png" style="width:150px; height:150px;">-->
<img id="move_to_right" src="f16.png" style="width:150px; height:150px;">
</div>
<div class="move_to_left">
<!--<img id="move" src="https://pngimage.net/wp-content/uploads/2018/05/f16-png-6.png" style="width:150px; height:150px;">-->
<img id="move_to_left" src="f162.png" style="width:150px; height:150px;">
</div>
</body></html>
Some issues:
you didn't close the #keyframes opening curly brace
both your keyframes had the same name examples
html {
height: 100%
}
body {
height: 100%;
width: 100%;
margin: 0;
background-repeat: no-repeat;
background-image: radial-gradient(black, white);
}
div.move_to_right {
width: auto;
height: auto;
position: absolute;
left: 200px;
}
.move_to_right {
position: absolute;
left: 200px;
}
#move_to_right {
width: 150px;
height: 150px;
position: relative;
-webkit-animation-name: move_to_right;
-webkit-animation-duration: 10s;
animation-name: move_to_right;
animation-duration: 3s;
animation-iteration-count: infinite;
}
#keyframes move_to_right {
0% {
opacity: 0.5;
transform: translate(-200px, 150px);
}
100% {
opacity: 1;
transform: translate(0px, 0px);
}
}
div.move_to_left {
width: auto;
height: auto;
position: absolute;
left: 200px;
}
.move_to_left {
position: absolute;
right: 200px;
}
#move_to_left {
width: 150px;
height: 150px;
position: relative;
-webkit-animation-name: move_to_left;
-webkit-animation-duration: 10s;
animation-name: move_to_left;
animation-duration: 3s;
animation-iteration-count: infinite;
}
#keyframes move_to_left {
0% {
opacity: 0.5;
transform: translate(200px, 150px);
}
100% {
opacity: 1;
transform: translate(0px, 0px);
}
}
<div class="move_to_right">
<img id="move_to_right" src="https://pngimage.net/wp-content/uploads/2018/05/f16-png-6.png" style="width:150px; height:150px;">
</div>
<div class="move_to_left">
<img id="move_to_left" src="https://pngimage.net/wp-content/uploads/2018/05/f16-png-6.png" style="width:150px; height:150px;">
</div>

Div always facing the screen inside a rotateY div

This is my code:
html
<div id="back">
<div id="right_text">TEST</div>
<div id="left_text">TEST2</div>
</div>
<div id="mid"></div>
css
#mid {
border: 1px solid black;
height: 100px;
width: 100px;
-webkit-animation: rotate linear 5s;
-webkit-animation-iteration-count: infinite;
margin:auto;
margin-top:-125px;
position: static;
}
#-webkit-keyframes rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#back {
width:auto;
height: 150px;
border: 1px solid red;
-webkit-animation: rotateY linear 5s;
-webkit-animation-iteration-count: infinite;
position: static;
}
#-webkit-keyframes rotateY {
from {
-webkit-transform: rotateY(0deg)
}
to {
-webkit-transform: rotateY(360deg)
}
}
#right_text {
border: 1px solid green;
height: 75px;
width: 75px;
float: right;
margin-top: 35px;
text-align: center;
}
#left_text {
border: 1px solid green;
height: 75px;
width: 75px;
float: left;
margin-top: 35px;
text-align: center;
}
http://jsfiddle.net/bXhL8/
As you can see, both text-divs face their back to the screen when they are not on their side of origin. i want both of them to always stay the same and just "hang on" to the rotation of my back-div.
my question would be if that is possible in css alone or if id need js for it.
Add the following to your css
#left_text, #right_text {
-webkit-animation: rotateY linear 5s;
-webkit-animation-iteration-count: infinite;
}
JSFiddle
Update
Updated JSFiddle
here is my new bit of code. its not a perfect circle yet, because i just added 4 frames to my #keyframes. im thinking about making a actual circular rotation and adding a skew() element to the whole circular function / to my whole body, don't know if that will work though.
thanks for your help!
html:
<div id="right_text">
<div id="right_text_text">TEST</div>
</div>
<div id="left_text">
<div id="left_text_text">TEST2</div>
</div>
<div id="mid"></div>
css:
#mid {
border: 1px solid black;
background-color: red;
height: 100px;
width: 100px;
-webkit-animation: rotate linear 5s;
-webkit-animation-iteration-count: infinite;
margin-top: 105px;
margin-left: 210px;
position: static;
}
#-webkit-keyframes rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(-360deg);
}
}
#right_text_text {
border: 1px solid black;
text-align: center;
position: absolute;
width: 50px;
-webkit-animation: downupright linear 8s infinite;
}
#left_text_text {
border: 1px solid black;
text-align: center;
position: absolute;
width: 50px;
-webkit-animation: updownleft linear 8s infinite;
}
#-webkit-keyframes downupright {
0% { left: 490px; top: 150px;}
25% { left: 245px; top: 100px; z-index: -10;}
50% { left: 0px; top: 150px;}
75% { left: 245px; top: 200px; z-index:10;}
100% { left: 490px; top: 150px;}
}
#-webkit-keyframes updownleft {
0% { left: 0px; top: 150px;}
25% { left: 245px; top: 200px; z-index: 9;}
50% { left: 490px; top: 150px;}
75% { left: 245px; top: 100px; z-index: -9;}
100% { left: 0px; top: 150px;}
}
http://jsfiddle.net/bXhL8/4/

Keyframes animation not working in Firefox

This animation is working perfectly in Safari and Chrome, but isn't working in Firefox.
I've tried a few things including -moz prefixes
Can anyone offer me advice on what's wrong here?
Here's the JSFiddle
HTML
<span class="awesome">
<span class="underline"></span>
<span class="underline2"></span>
awesome
</span>
CSS
span.awesome{
position: relative;
}
span.underline{
position: absolute;
top: 30px;
height: 1px;
background-color: black;
-webkit-animation: underline 2s linear infinite;
animation: underline 2s linear infinite;
}
span.underline2{
position: absolute;
top: 30px;
height: 1px;
background-color: black;
opacity: 0.2;
width: 110px;
}
#-webkit-keyframes underline{
0%{
width: 0px;
}
20%{
width: 0px;
}
28%{
width: 110px;
margin-left: 0;
}
36%{
width: 0px;
margin-left: 110px;
opacity: 0.8;
}
0%{
width: 0px;
}
}
#keyframes underline{
0%{
width: 0px;
}
20%{
width: 0px;
}
28%{
width: 110px;
margin-left: 0;
}
36%{
width: 0px;
margin-left: 110px;
opacity: 0.8;
}
0%{
width: 0px;
}
}
The problem was a typo – the last value read 0% instead of 100%
Don't need to specify -moz selectors for CSS3 animations in the latest versions of Firefox, but thanks for your suggestion, #Unykvis
Corrected CSS:
span.awesome{
position: relative;
}
span.underline{
position: absolute;
top: 30px;
height: 1px;
background-color: black;
-webkit-animation: underline 2s linear infinite;
animation: underline 2s linear infinite;
}
span.underline2{
position: absolute;
top: 30px;
height: 1px;
background-color: black;
opacity: 0.2;
width: 110px;
}
#-webkit-keyframes underline{
0%{
width: 0px;
}
20%{
width: 0px;
}
28%{
width: 110px;
margin-left: 0;
}
36%{
width: 0px;
margin-left: 110px;
opacity: 0.8;
}
100%{
width: 0px;
}
}
#keyframes underline{
0%{
width: 0px;
}
20%{
width: 0px;
}
28%{
width: 110px;
margin-left: 0;
}
36%{
width: 0px;
margin-left: 110px;
opacity: 0.8;
}
100%{
width: 0px;
}
}
Working JSFiddle
You need to add the -moz- to the keyframe animation and also to the selector.
Here is a working example: http://jsfiddle.net/ignaciocorreia/DxZps/4/
CSS:
span.underline{
position: absolute;
top: 30px;
height: 1px;
background-color: black;
-webkit-animation: underline 2s linear infinite;
-moz-animation: underline 2s linear infinite;
animation: underline 2s linear infinite;
}
#-moz-keyframes underline{
0%{
width: 0px;
}
20%{
width: 0px;
}
28%{
width: 110px;
margin-left: 0;
}
36%{
width: 0px;
margin-left: 110px;
opacity: 0.8;
}
0%{
width: 0px;
}
}