CSS background zoom animation jumps on mouse out - css

I have added a keyframe animation to slowly zoom the background image in and it works perfectly, however when I move mouse out the animation jumps back to the original state instead of zooming out.
#startup.hover:before {
opacity:1;
-webkit-animation: animatedBackground 5s ease-in-out 1;
-moz-animation: animatedBackground 5s ease-in-out 1;
animation: animatedBackground 5s ease-in-out 1;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
#-webkit-keyframes animatedBackground {
0% {
-webkit-transform: scale(1, 1);
-moz-transform: scale(1, 1);
-ms-transform: scale(1, 1);
-o-transform: scale(1, 1);
transform: scale(1, 1);
}
100% {
-webkit-transform: scale(1.1, 1.1);
-moz-transform: scale(1.1, 1.1);
-ms-transform: scale(1.1, 1.1);
-o-transform: scale(1.1, 1.1);
transform: scale(1.1, 1.1);
}
}
Am I missing something here?

first of all, is .hover a class you are adding or were you meant to use :hover? Just pointing this out. Assuming this is a class, you should add the transitions animation on the id.
#startup:before {
-webkit-transition: all 5s ease-in-out;
-moz-transition: all 5s ease-in-out;
-o-transition: all 5s ease-in-out;
transition: all 5s ease-in-out;
}
..this is why it's breaking when you are hovering out. There's no transition animation without the class!

You dont need such an advanced tool as a keyframes to make this effect.
It is easily achivable with transitions, here is an example.
https://jsfiddle.net/vqL3stjz/
.animable{
width: 100px;
height: 100px;
background-color: #000;
transition: all 500ms;
}
.animable:hover{
transform: scale(1.3, 1.3);
transition: all 500ms;
}
And if you need to make it with keyframes, then i suggest just applying reverse animation to unhovered element.
However, you will need to use some javascript then, to prevent side effect like animation running on the element right after it is loaded etc.
TL;DR Better use tranistions, unless you really need to use keyframes.

Related

How do I rotate an image at hover and every 10 seconds?

I made a css that can rotate my image when someone hover it
But I would rotate this image every 10 seconds too
.smiley-construct {
width: 64px;
padding: 0;
}
.smiley-construct img {
transition: 0.70s ease-in-out;
-webkit-transition: 0.70s;
-moz-transition: 0.70s;
-ms-transition: 0.70s;
-o-transition: 0.70s;
}
.smiley-construct img:hover {
transition: 0.70s ease-in-out;
-webkit-transition: 0.70s;
-moz-transition: 0.70s;
-ms-transition: 0.70s;
-o-transition: 0.70s;
transform: rotate(540deg);
-webkit-transform: rotate(540deg);
-moz-transform: rotate(540deg);
-o-transform: rotate(540deg);
-ms-transform: rotate(540deg);
}
<div class="smiley-construct">
<img src="https://quentinrenaux.com/wp-content/themes/quentinrenaux-V2.01.2021/img/smile/smile.png">
</div>
Can I change that to rotate my image every 10 seconds
but and keep the hover rotate too ?
Thanks
You can create a keyframe in css, something like this:
#keyframes rotating {
0% {
transform: rotate(0deg);
}
93% {
transform: rotate(0deg);
}
100% {
transform: rotate(540deg);
}
.smiley-construct img {
animation: rotating 10s infinite;
transition: 0.70s ease-in-out;
-webkit-transition: 0.70s;
-moz-transition: 0.70s;
-ms-transition: 0.70s;
-o-transition: 0.70s;
}
We can have two CSS animations - one which rotates the face then waits for the best part of 10s and keeps doing that and the other which kicks in on hover and just spins once.
I am not absolutely sure of the effect you want - is the face to go upside down after each rotate? You may want to play around with animation-fill-mode if not.
Here is a snippet:
.smiley-construct {
width: 64px;
padding: 0;
}
.smiley-construct img {
animation-name: spinwait;
animation-duration: 10s;
animation-iteration-count: infinite;
}
.smiley-construct img:hover {
animation-name: spin;
animation-duration: 0.7s;
animation-iteration-count: 1;
}
#keyframes spinwait {
0% {
transform: rotate(0deg);
}
7% {
transform: rotate(540deg);
}
7.1% {
transform: rotate(0deg);
}
100% {
transform: rotate(0deg);
}
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(540deg);
}
}
<div class="smiley-construct">
<img src="https://quentinrenaux.com/wp-content/themes/quentinrenaux-V2.01.2021/img/smile/smile.png">
</div>
You can make a function in javascript and make something like this:
Or make it jquery on when your page loads, but without knowing the structure and the resources available, I can not decide for you.
var elemPicture = document.getElementById("PictureId");
elemPicture.style.transition = "all 0.5s";
elemPicture.style.transform = "rotate(15deg)";
Better yet, use keyframes. No need to add extra JS if you can use CSS.
There's a pretty good explanation of how to do this here.

Restart CSS3 Animation without javascript?

Is it possible to "restart" a keyframe animation after it's stops with the same animation delay time again?
#keyframes scale {
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
.animated-btn {
animation: scale ease-in 1;
animation-fill-mode:forwards;
animation-duration: .6s;
animation-delay: 11.8s;
}
<a href="" class="btn btn__arrow animated-btn">
Aniamted Button
</a>
Unfortunately it's not possible to set a delay before each animation, but you can set a delay inside the animation. Just let the animation do nothing for a while until you reach a certain percentage.
Here's the updated code.
#keyFrames scale {
90% {
transform: scale(1)
}
95% {
transform: scale(1.3)
}
100% {
transform: scale(1);
}
}
.animated-btn {
display: inline-block;
animation: scale ease-in 1;
animation-fill-mode: forwards;
animation-duration: 12.4s;
animation-delay: 0s;
animation-iteration-count: infinite;
/* Or the shorthand:
animation: scale 1.4s 0s infinite ease-in forwards;
*/
}
Yes you just need to use the animation-iteration-count property.
You can set its value to infinite.

Perfomance of -webkit-keyframes

I have the following CSS animation:
.already-visible {
-webkit-transform: translateY(0);
-webkit-transform: translateX(0);
-webkit-animation: none;
-moz-transform: translateY(0);
-moz-transform: translateX(0);
-moz-animation: none;
}
.come-left-in {
display: block;
-webkit-transform: translateX(-1000px);
-webkit-animation: come-in 1s ease-out forwards;
-moz-transform: translateX(-1000px);
-moz-animation: come-in 1s ease forwards;
}
#-webkit-keyframes come-left-in {
to { -webkit-transform: translateX(0);
}
}
#-moz-keyframes come-left-in {
to { -moz-transform: translateX(0);
}
}
I used it to show the title of each section in the home page as the user scroll down (using scrollspy from Bootstrap 3). But when I scroll while the animation is running, I notice a lack of performance, like a little "jump". Is there a way to avoid this? I am thinking about using left css property animation instead translate transform, but I prefer to consult first this issue.
Thanks.
Use 3d transformations which are generally GPU accelerated (even if your transformation is 2d).
.already-visible {
-webkit-transform: translate3d(0, 0, 0);
-webkit-animation: none;
-moz-transform: translate3d(0, 0, 0);
-moz-animation: none;
}
.come-left-in {
display: block;
-webkit-transform: translate3d(-1000px, 0, 0);
-webkit-animation: come-in 1s ease-out forwards;
-moz-transform: translate3d(-1000px, 0, 0);
-moz-animation: come-in 1s ease forwards;
}
#-webkit-keyframes come-left-in {
to { -webkit-transform: translate3d(0, 0, 0);
}
}
#-moz-keyframes come-left-in {
to { -moz-transform: translate3d(0, 0, 0);
}
}
Read more on HTML5 Rocks
Also, here.
i dont know how webkit calculates transformations, but usually its done by multiplying matrices which can be very painful.
i would use margin-left though, instead of just left.
margin-left would calculate the distance from the parent element, works for me all the time for keyframe animations.

LESS - confusion about how mixins take parameters

I am using LESS and BOOTSTRAP for a website, and this is my first time actually using the less language, so this entire "mixins" thing is really confusing to me. I have read all of the documentation on the dotless website, and on the bootstrap site, but the actual "way" to use some of the mixins is escaping me.
In specific, I am having a hard time understanding how you discern what passes as a valid parameter. I am attempting to do with with transitions/transforms, using the following CSS...
-webkit-transform-origin: top;
-webkit-transition: all 0.2s linear;
-webkit-transform: scale(1, 0);
-webkit-animation-fill-mode: forwards;
-moz-transform-origin: top;
-moz-transition: all 0.2s linear;
-moz-transform: scale(1, 0);
-moz-animation-fill-mode: forwards;
-ms-transform-origin: top;
-ms-transition: all 0.2s linear;
-ms-transform: scale(1, 0);
-ms-animation-fill-mode: forwards;
-o-transform-origin: top;
-o-transition: all 0.2s linear;
-o-transform: scale(1, 0);
-o-animation-fill-mode: forwards;
transform-origin: top;
transition: all 0.2s linear;
transform: scale(1, 0);
animation-fill-mode: forwards;
From what I grasp, I am supposed to be able to do this in a much simpler format using the mixins built into bootstraps. The mixins are declared as follows;
// Transitions
.transition(#transition) {
-webkit-transition: #transition;
transition: #transition;
}
.transition-property(#transition-property) {
-webkit-transition-property: #transition-property;
transition-property: #transition-property;
}
.transition-delay(#transition-delay) {
-webkit-transition-delay: #transition-delay;
transition-delay: #transition-delay;
}
.transition-duration(#transition-duration) {
-webkit-transition-duration: #transition-duration;
transition-duration: #transition-duration;
}
.transition-transform(#transition) {
-webkit-transition: -webkit-transform #transition;
-moz-transition: -moz-transform #transition;
-o-transition: -o-transform #transition;
transition: transform #transition;
}
// Transformations
.rotate(#degrees) {
-webkit-transform: rotate(#degrees);
-ms-transform: rotate(#degrees); // IE9 only
transform: rotate(#degrees);
}
.scale(#ratio; #ratio-y...) {
-webkit-transform: scale(#ratio, #ratio-y);
-ms-transform: scale(#ratio, #ratio-y); // IE9 only
transform: scale(#ratio, #ratio-y);
}
.translate(#x; #y) {
-webkit-transform: translate(#x, #y);
-ms-transform: translate(#x, #y); // IE9 only
transform: translate(#x, #y);
}
.skew(#x; #y) {
-webkit-transform: skew(#x, #y);
-ms-transform: skewX(#x) skewY(#y); // See https://github.com/twbs/bootstrap/issues/4885; IE9+
transform: skew(#x, #y);
}
.translate3d(#x; #y; #z) {
-webkit-transform: translate3d(#x, #y, #z);
transform: translate3d(#x, #y, #z);
}
.rotateX(#degrees) {
-webkit-transform: rotateX(#degrees);
-ms-transform: rotateX(#degrees); // IE9 only
transform: rotateX(#degrees);
}
.rotateY(#degrees) {
-webkit-transform: rotateY(#degrees);
-ms-transform: rotateY(#degrees); // IE9 only
transform: rotateY(#degrees);
}
.perspective(#perspective) {
-webkit-perspective: #perspective;
-moz-perspective: #perspective;
perspective: #perspective;
}
.perspective-origin(#perspective) {
-webkit-perspective-origin: #perspective;
-moz-perspective-origin: #perspective;
perspective-origin: #perspective;
}
.transform-origin(#origin) {
-webkit-transform-origin: #origin;
-moz-transform-origin: #origin;
-ms-transform-origin: #origin; // IE9 only
transform-origin: #origin;
}
But I am not entirely clear on how this works. I cannot seem to figure out what "parameters" to pass through #transition and the like to make this code work. Can anyone help me out here? I am just kind of lost.
Whatever text you pass to an #variable when you use the mixin in a selector block will be copied to the places where the #variables appear in the mixins, and the contents of the mixins will be placed in your block. You can consider mixins somewhat like placeholder functions.
That means that if you declare a selector like:
div p:first-child {
.transition(width 2s ease-in-out, color 2s;);
color: red;
}
Using the .transition mixin you listed above, the Less processor will generate a CSS like:
div p:first-child {
-webkit-transition: width 2s ease-in-out, color 2s;
transition: width 2s ease-in-out, color 2s;
color: #FF0000;
}
The semicolon is important at the end of the argument otherwise Less may get confused and think you are sending two parameters, since comma-separated parameters are also valid. It won't be a problem in this case (since there is no .transition mixin that accepts two arguments), but it's good practice to always separate arguments with semicolons.
So to use the mixins, simply place them where you would add CSS declarations, end them with a semicolon, and pass the parameters as arguments.
Less does no duplication detection, so if you call the mixin twice, it just copies the replaced contents twice. If you already have a transition: property, for example, the mixin will add another one and its effect may be lost if yours comes after.
The best place to learn about Less, variables and mixins in at http://lesscss.org which has the full documentation in a few pages with plenty of examples. It's also great to have an editor which converts your Less files into CSS in real time so you understand how it works.
For the example you posted, you could create a mixin like the following:
.your-mixin(#origin, #transition, #transform, #anim-fill-mode) {
-webkit-transform-origin: #origin;
-webkit-transition: #transition;
-webkit-transform: #transform;
-webkit-animation-fill-mode: #anim-fill-mode;
-moz-transform-origin: #origin;
-moz-transition: #transition;
-moz-transform: #transform;
-moz-animation-fill-mode: #anim-fill-mode;
-ms-transform-origin: #origin;
-ms-transition: #transition;
-ms-transform: #transform;
-ms-animation-fill-mode: #anim-fill-mode;
-o-transform-origin: #origin;
-o-transition: #transition;
-o-transform: #transform;
-o-animation-fill-mode: #anim-fill-mode;
transform-origin: #origin;
transition: #transition;
transform: #transform;
animation-fill-mode: #anim-fill-mode;
}
To use it, you add it inside a selector block where you want the properties copied to:
.your-selector, .other-selector {
.your-mixin(top; all 0.2s linear; scale(1, 0); forwards;);
}

Why isn't -moz-animation working?

The following CSS works fine in Webkit. Haven't checked it in Opera, but I know it's not working in Firefox. Can anybody tell me why?
The correct classes are definitely getting applied to my HTML (inspected it with Firebug, and I do see the -moz-animation: 500ms ease 0s normal forwards 1 arrowRotateDot property on .arrow).
This also doesn't work in IE9, although I did originally have -ms-animation:... and -ms-transform:.... I thought it was supposed to work in IE9, but when it didn't I just assumed that IE didn't support these yet. However, now that it's not working in Firefox, maybe something else is going on.
.page.updatesPodcasts > .mainContent > .content .contentUpdates .disc.dot .dvd .arrow {
-webkit-animation: arrowRotateDot 500ms forwards;
-moz-animation: arrowRotateDot 500ms forwards;
-o-animation: arrowRotateDot 500ms forwards;
animation: arrowRotateDot 500ms forwards;
}
.page.updatesPodcasts > .mainContent > .content .contentUpdates .disc.f2 .dvd .arrow {
-webkit-animation: arrowRotateF2 500ms forwards;
-moz-animation: arrowRotateF2 500ms forwards;
-o-animation: arrowRotateF2 500ms forwards;
animation: arrowRotateF2 500ms forwards;
}
#-webkit-keyframes arrowRotateDot {
100% {
left:-18px; top:182px;
-moz-transform: scale(1) rotate(-30deg);
-webkit-transform: scale(1) rotate(-30deg);
-o-transform: scale(1) rotate(-30deg);
transform: scale(1) rotate(-30deg);
}
}
#-webkit-keyframes arrowRotateF2 {
0% {
left:-18px; top:182px;
-moz-transform: scale(1) rotate(-30deg);
-webkit-transform: scale(1) rotate(-30deg);
-o-transform: scale(1) rotate(-30deg);
transform: scale(1) rotate(-30deg);
}
100% {
left:115px; top:257px;
-moz-transform: scale(1) rotate(-90deg);
-webkit-transform: scale(1) rotate(-90deg);
-o-transform: scale(1) rotate(-90deg);
transform: scale(1) rotate(-90deg);
}
}
Your animations are not working in Firefox because you are using #-webkit-keyframes, which only applies to Webkit browsers, i.e. Chrome and Safari. The (somewhat) cross-browser way to do animation keyframes is:
#keyframes animationName {
/* animation rules */
}
#-moz-keyframes animationName {
/* -moz-animation rules */
}
#-webkit-keyframes animationName {
/* -webkit-animation rules */
}
Opera and Internet Explorer do not currently support the #keyframes rule.
Skyline is correct. Firefox does not support this, so you will need additional code to get the same or similar effects if they exist without webkit.
Also, here is some additional information that might help you with your code or help you in deciding where to go from this point with your code if adding additional code is not an option (I ended up changing how I code to keep from being overwhelmed with code):
http://caniuse.com/#
http://www.quirksmode.org/webkit.html

Resources