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.
}
Related
How can I make my button decrease size on hover as per this pen here looking at the pulse button?
My CSS looks like this:
.pulse {
margin:100px;
display: block;
width: 170px;
height: 22px;
background: #cca92c;
cursor: pointer;
box-shadow: 0 0 0 rgba(204,169,44, 0.4);
}
.pulse:hover {
animation: pulse 2s infinite;
}
#keyframes pulse {
0%{
width: 170px;
}
50%{
width: 120px;
}
}
HTML:
<button class="pulse">Button styling</button>
When I hover, the width decreases, but the effect is not the same as the reference pen which gets smaller on all sides, if that's the correct explanation.
My pen can be found here
try to add transform to get the animation
.pulse {
margin: 100px;
display: block;
width: 170px;
height: 22px;
border-radius: 50%;
background: #cca92c;
cursor: pointer;
box-shadow: 0 0 0 rgba(204, 169, 44, 0.4);
animation: pulse 2s infinite;
}
.pulse:hover {
animation: none;
}
#keyframes pulse {
0% {
transform: scale(1);
}
70% {
transform: scale(.9);
}
100% {
transform: scale(1);
}
}
<button class="pulse">Button styling</button>
I want to add an loader in my angular 4 PWA. https://www.w3schools.com/howto/howto_css_loader.asp this loader is visible till all the contents of page get loaded.
<div *ngIf="isLoaded" class="loader"></div>
<div class="home-container" [hidden]="isLoaded"></div>
Initially isLoaded is true after loading all contents it will become false.
loader poistion => top => 0, right = 50%, left = 50%, bottom= 100%
.scss file
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #59d4bf; /* green */
border-radius: 50%;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
here -stackblitz live code sample
Your should put your css,
margin-right: 50%; or margin-right: auto;
margin-top: 50%;
margin-left: 50%; or margin-right: auto;
your loader
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
margin-left: 50%;
margin-right: 50%;
margin-top: 50%;
}
is it working , Live working code sample
I have a small horizontal notification bar that slides up from the bottom of the page.
It comes up fine, but when you open up the page it quickly flashes, then disappears and then slides up.
How do I modify it so it doesn't appear/disappear before the transition takes place?
#notificationBarBottom {
position: fixed;
z-index: 101;
bottom: 0;
left: 0;
right: 0;
background: #5cb85c;
color: #ffffff;
text-align: center;
line-height: 2.5;
overflow: hidden;
-webkit-box-shadow: 0 0 5px black;
-moz-box-shadow: 0 0 5px black;
box-shadow: 0 0 5px black;
}
#-webkit-keyframes slideDown {
0%, 100% {
-webkit-transform: translateY(0px);
}
10%,
90% {
-webkit-transform: translateY(510px);
}
}
#-moz-keyframes slideDown {
0%, 100% {
-moz-transform: translateY(0px);
}
10%,
90% {
-moz-transform: translateY(510px);
}
}
.cssanimations.csstransforms #notificationBarBottom {
-webkit-transform: translateY(510px);
-webkit-animation: slideDown 2.5s 1.0s 1 ease forwards;
-moz-transform: translateY(510px);
-moz-animation: slideDown 2.5s 1.0s 1 ease forwards;
}
<div id="notificationBarBottom">Hello, human!</div>
Jsfiddle demo here: https://jsfiddle.net/cnfk36jd/ (but unfortunately the problem is not visible there). Here's the page where you can see the "flickering" http://www.whycall.me/bannerTest.html
I tried the advice here: https://css-tricks.com/pop-from-top-notification/ and tweaked the translateY values quite a bit, but it doesn't help, not sure what else to do.
Thank you for your help
The elements initial position is visible, and then, during page load, the first translate kicks in to hide it, hence it flickers.
Do like this, push it out of view using transform: translateY(calc(100% + 10px)); and then slide it up with transform: translateY(0));.
I used 100% instead of -510px to make it height independent, and added 10px to make up for the top shadow.
I also temporary removed the prefixed properties, so you need to add them back
Updated 2021: Updated answer, improved the code suggestion, and, based on a comment, added how to make it hide using a click
document.getElementById('notificationBarBottom').addEventListener('click', function() {
this.classList.add('hideMe');
})
#notificationBarBottom {
position: fixed;
z-index: 101;
bottom: 0;
transform: translateY(calc(100% + 10px));
left: 0;
right: 0;
background: #5cb85c;
color: #ffffff;
text-align: center;
line-height: 2.5;
overflow: hidden;
box-shadow: 0 0 5px black;
}
#keyframes slideUp {
0% { transform: translateY(100% + 10px); }
100% { transform: translateY(0); }
}
#notificationBarBottom {
animation: slideUp 2.5s ease forwards;
}
#close {
display: none;
}
/* added to show how to hide with a click */
#keyframes slideDown {
0% { transform: translateY(0); }
100% { transform: translateY(100% + 10px); }
}
#notificationBarBottom.hideMe {
animation: slideDown 2.5s ease forwards;
}
<div id="notificationBarBottom">Hello, human!</div>
I think this is happening because the css file in which you've written this code is called a bit too late.
In your html page, try calling this css file earlier than other css or JS files
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 am trying to achieve an infinite blink and rotation together, but the problem I face is quite weird, the blinking which should occur at a regular interval of 500ms, happens nicely for a while then disappears and appears back again.
Also I went through lot of questions around blinking but my test case is different. I can't keep the 0% 50% 100% in the keyframes to get the blinking working because I'd want the span to blink at a particular percentage I specify.
For example: I'd want the span to blink at 100deg or 90deg, so I should be able to specify the blink timing by specifying the exact percentage value.
Here's my work so far, any help would be appreciated. http://jsfiddle.net/8UQ8X/7/ (includes vendor prefixes)
<div>
<span></span>
</div>
<style>
div{
position: fixed;
width:3px;
height:100px;
left: 300px;
top: 100px;
border: 1px rgba(255,255,255,0.1) solid;
-webkit-animation: spin 500ms steps(30) infinite;
-webkit-transform-origin: center center;
-webkit-transform: translate3d(0, 0, 0);
}
span{
display:block;
width: 2px;
height: 2px;
border-radius: 50%;
-webkit-animation: blink 500ms infinite steps(1);
}
#-webkit-keyframes spin {
from{
-webkit-transform: rotate(0deg)
}
to{
-webkit-transform: rotate(360deg)
}
}
#-webkit-keyframes blink {
// I should be able to any percentage value to get the span blink at a particular degree.
// for now I am trying to blink the span at 0%, the beginning, later I might change it to 50% or something
0% {background: #fff}
1% {background: none;}
}
body{
background: #232323;
}
</style>
Try this : Animation
.i{
position: fixed;
width:10px;
height:150px;
left: 300px;
top: 100px;
border: 1px rgba(255,255,255,0.1) solid;
-webkit-animation: spin 500ms steps(30) infinite;
-webkit-transform-origin: center center;
-webkit-transform: translate3d(0, 0, 0);
-moz-animation: spin 500ms steps(30) infinite;
-moz-transform-origin: center center;
-moz-transform: translate3d(0, 0, 0);
-webkit-animation-timing-function:ease-in-out;
}
span{
display:block;
width: 10px;
height: 10px;
border: 1px rgba(255,255,255,0.1) solid;
border-radius: 50%;
-webkit-animation: blink 500ms infinite steps(1);
-moz-animation: blink 500ms infinite steps(1);
-webkit-animation-timing-function:liner;
}
#-webkit-keyframes spin {
from{
-webkit-transform: rotate(0deg)
}
to{
-webkit-transform: rotate(360deg)
}
}
#-moz-keyframes spin {
from{
-moz-transform: rotate(0deg)
}
to{
-moz-transform: rotate(360deg)
}
}
#-webkit-keyframes blink {
0% {background: #fff}
1% {background: none;}
}
#-moz-keyframes blink {
0% {background: #fff}
1% {background: none;}
}
body{
background: #232323;
}