iframe {
box-shadow: 0 10px 18px 0 rgba(0, 0, 0, 0.144),
0 12px 30px 0 rgba(0, 0, 0, 0.377);
}
iframe:hover {
filter: brightness(95%);
transition: 0.5s ease-in-out;
animation: iframes 0.8s linear both 1;
box-shadow: 0 12px 24px 0 rgba(0, 0, 0, 0.212),
0 16px 35px 0 rgba(0, 0, 0, 0.493);
}
#keyframes iframes {
0% {
transform: rotate(0deg);
}
25% {
transform: rotate(7deg);
}
50% {
transform: rotate(0deg);
}
75% {
transform: rotate(-7deg);
}
100% {
transform: rotate(0deg) ;
}
}
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d14023.546898520377!2d77.2038604!3d28.5130556!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xd87ca9af3beebff5!2sShrishti%20Flower!5e0!3m2!1sen!2sin!4v1613667773659!5m2!1sen!2sin" width="60%" height="400" frameborder="0" style="border:2.7px blue solid; margin-bottom: 2rem; border-radius: 1rem; " allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>
<!-- iframe --!>
when I hover on this iframe it starts to shaking rapidly and the animation trigger more than once. I don't know why this happens . pls help me to solve it.
The shaking rapidly part I do not experience with your code snippet, the repeated animation is caused by having the animation on hover, this will reset the count everytime a user hovers the iframe.
By setting the animation on the iframe itself you can prevent this. You set start the animation on hover with animation-play-state.
iframe {
box-shadow: 0 10px 18px 0 rgba(0, 0, 0, 0.144),
0 12px 30px 0 rgba(0, 0, 0, 0.377);
animation: iframes 0.8s linear both 1;
animation-play-state: paused;
}
iframe:hover {
filter: brightness(95%);
transition: 0.5s ease-in-out;
animation-play-state: running;
box-shadow: 0 12px 24px 0 rgba(0, 0, 0, 0.212),
0 16px 35px 0 rgba(0, 0, 0, 0.493);
}
#keyframes iframes {
0% {
transform: rotate(0deg);
}
25% {
transform: rotate(7deg);
}
50% {
transform: rotate(0deg);
}
75% {
transform: rotate(-7deg);
}
100% {
transform: rotate(0deg) ;
}
}
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d14023.546898520377!2d77.2038604!3d28.5130556!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xd87ca9af3beebff5!2sShrishti%20Flower!5e0!3m2!1sen!2sin!4v1613667773659!5m2!1sen!2sin" width="60%" height="400" frameborder="0" style="border:2.7px blue solid; margin-bottom: 2rem; border-radius: 1rem; " allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>
Please add "animation-iteration-count" to "infinite" for the shaking rapidly.
iframe {
box-shadow: 0 10px 18px 0 rgba(0, 0, 0, 0.144),
0 12px 30px 0 rgba(0, 0, 0, 0.377);
}
iframe:hover {
filter: brightness(95%);
transition: 0.5s ease-in-out;
animation: iframes 0.8s linear both 1;
box-shadow: 0 12px 24px 0 rgba(0, 0, 0, 0.212),
0 16px 35px 0 rgba(0, 0, 0, 0.493);
animation-iteration-count:infinite;
}
#keyframes iframes {
0% {
transform: rotate(0deg);
}
25% {
transform: rotate(7deg);
}
50% {
transform: rotate(0deg);
}
75% {
transform: rotate(-7deg);
}
100% {
transform: rotate(0deg) ;
}
}
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d14023.546898520377!2d77.2038604!3d28.5130556!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xd87ca9af3beebff5!2sShrishti%20Flower!5e0!3m2!1sen!2sin!4v1613667773659!5m2!1sen!2sin" width="60%" height="400" frameborder="0" style="border:2.7px blue solid; margin-bottom: 2rem; border-radius: 1rem; " allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>
I have this animation working in Chrome and Android, while in Safari and iOS rings are not fading away but staying black. What is causing that?
Is there way not to use box-shadow and achieve same effect?
https://codepen.io/anon/pen/oVZWQa
<div class="loader">
<span class="ring ring-1"></span>
<span class="ring ring-2"></span>
<span class="ring ring-3"></span>
<span class="ring ring-4"></span>
</div>
#yellow: #FFD200;
#brown: darken(#yellow, 45%);
body {
background: fade(#yellow, 90%);
}
.loader {
position: relative;
width: 20rem;
height: 20rem;
.ring {
position: absolute;
border-radius: 50%;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
animation: pulse 8s ease-out infinite;
&.ring-2 {
animation-delay: 2000ms
}
&.ring-3 {
animation-delay: 4000ms
}
&.ring-4 {
animation-delay: 6000ms
}
}
#keyframes pulse {
0% {
box-shadow: 0 0 0 60px #brown;
transform: scale(0);
opacity: 0;
}
25% {
box-shadow: 0 0 0 45px rgba(darken(#yellow, 40%), 0.66);
opacity: 1;
}
50% {
box-shadow: 0 0 0 25px rgba(darken(#yellow, 30%) 0.33);
}
100% {
box-shadow: 0 0 0 1px rgba(darken(#yellow, 20%) 0);
transform: scale(1);
}
}
}
as #Turnip pointed out I had missing commas.
I making a button with animated img on it. So when you hover on, car goes from left, and stops in center. And when you hover out - car goes to right.
I've made a fiddle:
https://jsfiddle.net/ufwyjd0o/
.button{
height:150px;
width: 150px;
background-color:#468189;
margin: 100px;
border-radius: 100%;
box-shadow: 0px 3px 8px 0px rgba(0,0,0,0.6);
animation: size 1.5s infinite alternate;
position: relative;
}
#keyframes size {
0% {transform: scale(1.0);
box-shadow: 0px 3px 8px 0px rgba(0,0,0,0.6); }
100% {transform: scale(1.05);
box-shadow: 0px 8px 8px 0px rgba(0,0,0,0.4); }
}
.icon img{
height:75px;
width:auto;
position: absolute;
top: 40px;
animation: driveout 1s cubic-bezier(.52,.02,.31,.99) both;
transform: 1s;
}
#keyframes drive {
0% {transform: translate3d(-60px,0,0)}
5% {transform: translate3d(60px,0,0)}
10% {transform: translate3d(40px,0,0);}
}
#keyframes driveout {
0% {transform: translate3d(40px,0,0)}
100% {transform: translate3d(200px,0,0)}
}
.button:hover .icon img {
animation: drive 10s cubic-bezier(.52,.02,.31,.99) normal;
animation-play-state: pause;
display:block;
}
If you want different animations on hoveron and hoverout (same as mouseover and mouseout in javascript) then your best bet would be something like this.
.button {
// what you want to happen on hoverout
animation: // your hoverout animation
}
.button:hover {
// what you want to happen on hoverover
animation: // your hoverover animation.
}
Having an issue with my CSS3 animation in Firefox and Safari. It works like a charm in Chrome and Internet Explorer. Spent a while attempting to figure this out myself, but no success. I followed all of the rules I could find, but I must be missing something.
HTML
<div class="background">
<div id="canvas" class="loading"></div>
CSS
.background {
background:#333;
padding-bottom: 140px;
padding-top: 65px;
}
#canvas.loading {
-webkit-animation: animate 1.5s linear infinite;
-moz-animation: animate 1.5s linear infinite;
animation: animate 1.5s linear infinite;
clip: rect(0, 80px, 80px, 40px);
height: 80px;
width: 80px;
position:absolute;
left:45%;
}
#-webkit-keyframes animate {
0% {
transform: rotate(0deg)
}
100% {
transform: rotate(220deg)
}
}
#keyframes animate {
0% {
transform: rotate(0deg)
}
100% {
transform: rotate(220deg)
}
}
#-moz-keyframes animate {
0% {
transform: rotate(0deg)
}
100% {
transform: rotate(220deg)
}
}
#canvas.loading:before {
-webkit-animation: animate2 1.5s ease-in-out infinite;
-moz-animation: animate 1.5s linear infinite;
animation: animate2 1.5s ease-in-out infinite;
clip: rect(0, 80px, 80px, 40px);
content:'';
border-radius: 50%;
height: 80px;
width: 80px;
position:absolute
}
#-webkit-keyframes animate2 {
0% {
box-shadow: inset #5AA0E7 0 0 0 17px;
transform: rotate(-140deg);
}
50% {
box-shadow: inset #5AA0E7 0 0 0 2px;
}
100% {
box-shadow: inset #5AA0E7 0 0 0 17px;
transform: rotate(140deg);
}
}
#-moz-keyframes animate2 {
0% {
box-shadow: inset #5AA0E7 0 0 0 17px;
transform: rotate(-140deg);
}
50% {
box-shadow: inset #5AA0E7 0 0 0 2px;
}
100% {
box-shadow: inset #5AA0E7 0 0 0 17px;
transform: rotate(140deg);
}
}
#keyframes animate2 {
0% {
box-shadow: inset #5AA0E7 0 0 0 17px;
transform: rotate(-140deg);
}
50% {
box-shadow: inset #5AA0E7 0 0 0 2px;
}
100% {
box-shadow: inset #5AA0E7 0 0 0 17px;
transform: rotate(140deg);
}
}
Here is the JSFIDDLE: http://jsfiddle.net/myo4r9kk/
Any help would be greatly appreciated!
Works for me in FF 35, can't say more than that.
Safari needs the transform property to be prefixed, so changing your css to the following will make it work (only included the relevant parts):
#-webkit-keyframes animate {
0% {
-webkit-transform: rotate(0deg)
transform: rotate(0deg)
}
100% {
-webkit-transform: rotate(220deg)
transform: rotate(220deg)
}
}
#-webkit-keyframes animate2 {
0% {
box-shadow: inset #5AA0E7 0 0 0 17px;
-webkit-transform: rotate(-140deg);
transform: rotate(-140deg);
}
50% {
box-shadow: inset #5AA0E7 0 0 0 2px;
}
100% {
box-shadow: inset #5AA0E7 0 0 0 17px;
-webkit-transform: rotate(140deg);
transform: rotate(140deg);
}
}
It's probably best to change your #keyframes in the same way, just in case Safari one day supports unprefixed #keyframes but still needs prefixed transform rule.
And one last thing: It is generally considered safest to put the prefixed versions of a property before the standard version. I'm not totally sure but I guess that applies to keyframes as well, so you might want to put your #-moz-keyframes before your #keyframes. That may even solve your problems with Firefox (assuming a working implementation of the standard gets overwritten by a buggy version because you put the prefixed after the standard.
I took the liberty to update your fiddle with all those changes: http://jsfiddle.net/myo4r9kk/2/
EDIT
I just found this in your code:
-webkit-animation: animate2 1.5s ease-in-out infinite;
-moz-animation: animate 1.5s linear infinite;
animation: animate2 1.5s ease-in-out infinite;
Maybe that explains the problems with Firefox, are you by any chance testing this on FF < 15? In any case that -moz-animation should be the same as the other two.
I want to make a CSS3 animation where a div gets a box shadow on mouse over, and loses it on mouse out. This is what I have so far:
HTML:
<div id="page">
<div id="container" onmouseover="mouseOverContainer()" onmouseout="mouseOutContainer()" class="">
</div>
</div>
JS:
var container = undefined;
function assignContainer() {
if(container===undefined) {
container = document.getElementById("container");
}
}
function mouseOverContainer() {
assignContainer();
container.className="container-in";
}
function mouseOutContainer() {
assignContainer();
container.className="container-out";
}
CSS:
#keyframes box-shadow-anim-in{
from {
box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
margin-top: 20px;
}
to {
box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
margin-top: 18px;
}
}
#-o-keyframes box-shadow-anim-in{
from {
-o-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
to {
-o-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
}
#-webkit-keyframes box-shadow-anim-in{
from {
-webkit-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
to {
-webkit-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
}
#-ms-keyframes box-shadow-anim-in{
from {
-ms-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
to {
-ms-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
}
#-moz-keyframes box-shadow-anim-in {
from {
-moz-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
to {
-moz-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
}
#keyframes box-shadow-anim-out{
from {
box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
to {
box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
}
#-moz-keyframes box-shadow-anim-out{
from {
-moz-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
to {
-moz-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
}
#-o-keyframes box-shadow-anim-out{
from {
-o-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
to {
-o-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
}
#-webkit-keyframes box-shadow-anim-out {
from {
-webkit-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
to {
-webkit-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
}
#-ms-keyframes box-shadow-anim-out{
from {
-ms-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
to {
-ms-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
}
#page {
width: 900px;
margin: 0 auto;
}
#container {
width: 60%;
height: 250px;
background-color: #ccc;
margin-top: 20px;
border: 1px solid #999;
}
.container-out {
animation: box-shadow-anim-out 0.3s;
-moz-animation: box-shadow-anim-out 0.3s;
-webkit-animation: box-shadow-anim-out 0.3s;
-o-animation: box-shadow-anim-out 0.3s;
-ms-animation: box-shadow-anim-out 0.3s;
animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
-o-animation-fill-mode: forwards;
-ms-animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
}
.container-in {
animation: box-shadow-anim-in 0.3s;
-moz-animation: box-shadow-anim-in 0.3s;
-webkit-animation: box-shadow-anim-in 0.3s;
-o-animation: box-shadow-anim-in 0.3s;
-ms-animation: box-shadow-anim-in 0.3s;
animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
-o-animation-fill-mode: forwards;
-ms-animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
}
Everything works fine, as you can see in this JSFiddle.
But, as you can see, we have to define browser-specific keyframes in order to make it work on all browsers.
It's a bit boring, especially when you have to change one small detail in one animation, because you have to change all other browser-specific animations too.
I thought I could use just one block, inserting all keyframes separated by comma, like this:
#keyframes box-shadow-anim-in,
#-o-keyframes box-shadow-anim-in,
#-webkit-keyframes box-shadow-anim-in,
#-ms-keyframes box-shadow-anim-in,
#-moz-keyframes box-shadow-anim-in {
from {
box-shadow: 0 0 0 rgba(0,0,0,0.0);
-o-box-shadow: 0 0 0 rgba(0,0,0,0.0);
-webkit-box-shadow: 0 0 0 rgba(0,0,0,0.0);
-ms-box-shadow: 0 0 0 rgba(0,0,0,0.0);
-moz-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
to {
box-shadow: 0 0 250px rgba(127,127,127,1.0);
-o-box-shadow: 0 0 250px rgba(127,127,127,1.0);
-webkit-box-shadow: 0 0 250px rgba(127,127,127,1.0);
-ms-box-shadow: 0 0 250px rgba(127,127,127,1.0);
-moz-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
}
#keyframes box-shadow-anim-out,
#-o-keyframes box-shadow-anim-out,
#-webkit-keyframes box-shadow-anim-out,
#-ms-keyframes box-shadow-anim-out,
#-moz-keyframes box-shadow-anim-out {
from {
box-shadow: 0 0 250px rgba(127,127,127,1.0);
-o-box-shadow: 0 0 250px rgba(127,127,127,1.0);
-webkit-box-shadow: 0 0 250px rgba(127,127,127,1.0);
-ms-box-shadow: 0 0 250px rgba(127,127,127,1.0);
-moz-box-shadow: 0 0 250px rgba(127,127,127,1.0);
background-color: #efefef;
margin-top: 18px;
}
to {
box-shadow: 0 0 0 rgba(0,0,0,0.0);
-o-box-shadow: 0 0 0 rgba(0,0,0,0.0);
-webkit-box-shadow: 0 0 0 rgba(0,0,0,0.0);
-ms-box-shadow: 0 0 0 rgba(0,0,0,0.0);
-moz-box-shadow: 0 0 0 rgba(0,0,0,0.0);
background-color: #ccc;
margin-top: 20px;
}
}
But this doesn't seem to work (JSFiddle here), so maybe I'm doing something wrong or I just can't do it like this.
Is it possible to do something like this? If yes, how?
No, it's not possible with CSS. You can't group different at-rules together, much like how you can't group vendor-prefixed selectors.
You could resort to using a Sass/LESS mixin, but that's assuming you're working with a preprocessor already, and that just outputs separate duplicate CSS rules anyway.
For what it's worth, there are several prefixes that can be removed to reduce some of the bloat in your CSS:
#-ms-keyframes and -ms-animation are not used by any stable version of IE; IE10 supports them unprefixed right out of the box
Firefox also supports unprefixed #keyframes/animation, starting from version 16
-ms-box-shadow and -o-box-shadow have never existed, so they should be removed/unprefixed
-moz-box-shadow is only required by Firefox 3.5 and 3.6, neither of which support CSS animations (not even via #-moz-keyframes — that was added in version 5), so it should be unprefixed
You should also place the prefixless item last instead of first, to ensure (by the cascade) that it takes precedence over the prefixed item in browsers that support it.
This is not possible without a preprocessor such as SASS or LESS.
But, there is another option using JS. Take a look here: http://leaverou.github.io/prefixfree/
I would personally suggest you switch over to a CSS preprocessor, as it will undoubtedly be handy in the future.