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
Related
In a moving box,
I want to make an animation that turns upside down when I raise the mouse.
I want to implement the movement of the box with the keyframe and designate hover, but it doesn't work.
What should I do?
#www{
background-color: black;
position: absolute;
left: 0;
top: 0;
animation: www 5s infinite;
transition: 1s;
}
#www:hover{
transform: rotate(180deg);
}
#keyframes www{
0% {
transform: translateX(0vw);
}
50% {
transform: translateX(50vw);
}
100% {transform: translateX(0vw);}
}
<div class="box" id="www">WWW</div>
You can use a container to have both transformation properties as you can't achieve different transform on same element using different triggers(hover automatic)
Below styles used are for illustration only (to easily understand) you can use according to need and have a transparent background if want
function func() {
document.getElementById("www").style.transform = "rotate(180deg)"
}
#www {
background-color: black;
transition: 1s transform;
animation: www 10s infinite;
width: fit-content;
}
#keyframes www {
0% {
transform: translateX(0vw);
}
50% {
transform: translateX(50vw);
}
100% {
transform: translateX(0vw);
}
}
.box1 {
transition: 1s;
background-color: red;
margin-top: 100px;
width: fit-content;
}
.box1:hover {
transform: rotate(180deg)
}
<div class="box" id="www" onclick="func()">
<div class="box1">WWW</div>
</div>
I'm trying to perform a simple CSS transform on :hover — which is obviously an easy task usually but I'm trying to do it on an animating div element. The element is infinitely animating on the Y axis with a simple CSS animation using #keyframes{}, but when I attempt to hover over the element nothing happens.
I can get it to kind of work if I use !important on the hover code, but the transform/scale happens instantly instead of using the 300ms transition property that I've applied to the .box class.
Am I missing something obvious, or is this not possible? Essentially I just want the element to scale on hover using the transition effect and timing, but then resume it's original animation when not hovered. Thanks
.box {
width: 50%;
border: solid 3px #555;
animation: box-move 1s infinite alternate-reverse;
transition: transform 300ms;
}
.box:hover {
transform: scale(1.2);
}
#keyframes box-move {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-5px);
}
}
<div class="box">I'm a box. I move up and down, but I don't scale nicely when hovered like I should :(</div>
Because you are using transform property on hover and in animation both.
Try this one.
.box {
width: 50%;
border: solid 3px #555;
animation: box-move 1s infinite alternate-reverse;
transition: transform 300ms;
}
.box:hover {
animation: box-move-anim 1s infinite alternate-reverse;
}
#keyframes box-move {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-5px);
}
}
#keyframes box-move-anim {
0% {
transform: translateY(0) scale(1);
}
100% {
transform: translateY(-5px) scale(1.2);
}
}
Consider another wrapper:
.box {
width: 50%;
animation: box-move 1s infinite alternate-reverse;
}
.box> div {
border: solid 3px #555;
transition: transform 300ms;
transform-origin:top left;
}
.box:hover > div {
transform: scale(1.2);
}
#keyframes box-move {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-5px);
}
}
<div class="box"><div>I'm a box. I move up and down, but I don't scale nicely when hovered like I should :(</div></div>
Ok, so thanks to your clever and helpful suggestions I managed to find a satisfactory solution. The key for me was using the animation-direction property set to forwards on the :hover. I can't really explain why this works but all I know that it doesn't work properly without it.
I would still ideally like the scale out (hover off) to be as smooth as the scale in (it currently just snaps back), but this will do for my needs.
Thanks again.
.box {
width: 50%;
margin: 1em auto 0 auto;
border: solid 3px #555;
cursor: pointer;
animation: box-move 1s infinite alternate-reverse;
}
.box:hover {
animation: box-move-anim 300ms 1 forwards;
}
#keyframes box-move {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-5px);
}
}
#keyframes box-move-anim {
0% {
transform: scale(1);
}
100% {
transform: scale(1.2);
}
}
<div class="box">I'm a box that animates up and down, but I now smoothly scale when hovered :)</div>
I implemented this nice little css-based loader I found and then realized it doesn't work on IE (I tried IE11). I thought maybe it needed the vendor specific prefixes, so I tried using an online autoprefixer using 'last 2 versions' as the filter and it adds '-webkit-' prefixes but not the '-ms-' which makes me wonder if there something wrong with the way the css code is written that makes the '-ms-' prefixes not show up. I tried manually replacing the '-webkit-' with '-ms-' but it still doesn't work on IE.
What is preventing this from working on IE?
Does the vendor prefixing have anything to do with it or not?
I haven't tried on any browser other than Chrome and IE at this point but would like to make it work on all major browsers last 2 versions if that is reasonable.
Original CSS - works great on Chrome but not on IE:
.page-loader{ background: #f9f9f9 none repeat scroll 0 0;
height: 100%;
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 9998;}
.loader {
height: 8px;
margin: 0 auto;
position: relative;
text-align: center;
top: 50%;
width: 44px;
}
.dot {
background: #ccc none repeat scroll 0 0;
border-radius: 50%;
display: inline-block;
height: 10px;
position: absolute;
width: 10px;
}
.dot_1 {
animation: 1.5s linear 0s normal none infinite running animateDot1;
background: #f26f29 none repeat scroll 0 0;
left: 12px;
}.dot_2 {
animation: 1.5s linear 0.5s normal none infinite running animateDot2;
left: 24px;
}.dot_3 {
animation: 1.5s linear 0s normal none infinite running animateDot3;
left: 12px;
}.dot_4 {
animation: 1.5s linear 0.5s normal none infinite running animateDot4;
left: 24px;
}
#keyframes animateDot1 {
0% {
transform: rotate(0deg) translateX(-12px);
}
25% {
transform: rotate(180deg) translateX(-12px);
}
75% {
transform: rotate(180deg) translateX(-12px);
}
100% {
transform: rotate(360deg) translateX(-12px);
}
}
#keyframes animateDot2 {
0% {
transform: rotate(0deg) translateX(-12px);
}
25% {
transform: rotate(-180deg) translateX(-12px);
}
75% {
transform: rotate(-180deg) translateX(-12px);
}
100% {
transform: rotate(-360deg) translateX(-12px);
}
}
#keyframes animateDot3 {
0% {
transform: rotate(0deg) translateX(12px);
}
25% {
transform: rotate(180deg) translateX(12px);
}
75% {
transform: rotate(180deg) translateX(12px);
}
100% {
transform: rotate(360deg) translateX(12px);
}
}
#keyframes animateDot4 {
0% {
transform: rotate(0deg) translateX(12px);
}
25% {
transform: rotate(-180deg) translateX(12px);
}
75% {
transform: rotate(-180deg) translateX(12px);
}
100% {
transform: rotate(-360deg) translateX(12px);
}
}
Perhaps try removing the running values from your animation properties. This makes the animation work for me in IE11.
I see that there's some discussion of this issue here:
"CSS3 animation is not working in IE11 but works in other browsers"
Trying to do some CSS3 transitions and animations using 2 images.
Our requirement is
First display the background image
Move it slightly on the northward direction
Display the background image for few seconds (pause effect)
After few seconds introduce the foreground image (fade in effect)
Slightly move the image in northward direction
Fade out the foreground image
But we are unable to achieve the above exactly. Currently the background and foreground image are moving almost at the same time, unable to achieve the 'fade in' effect for the foreground image.
Demo Link: https://jsfiddle.net/sandeepskm/kLtyssjc/
Please help us out.
Our code
HTML5 Code
<div id="a" class="animated slideInUp">
<div id="b" class="animated slideInUpChild">
<img src="https://cdn3.iconfinder.com/data/icons/black-easy/512/535106-user_512x512.png" width="150px" alt="" />
</div>
</div>
CSS3 Code
#a
{
width: 100%;
height: 600px;
margin: 0 0 0 0;
padding: 0 0 0 0;
position: relative;
background-image: url(http://webneel.com/wallpaper/sites/default/files/images/08-2013/11-sea-beach-sand-wallpaper.jpg);
}
#b
{
width: 100%;
height: 10px;
margin: 0 0 0 0;
padding: 0 0 0 0;
position: absolute;
bottom: 0;
}
.animated
{
-webkit-animation-duration: 1s;
animation-duration: 1s;
}
.slideInUp
{
-webkit-animation-name: slideInUp;
animation-name: slideInUp;
-webkit-animation-duration: 1s;
animation-duration: 1s;
}
.slideInUpChild
{
-webkit-animation-name: slideInUpChild;
animation-name: slideInUpChild;
-webkit-animation-delay: 1s;
animation-delay: 1s;
}
#keyframes slideInUp
{
from
{
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to
{
-webkit-transform: translate3d(0, 10%, 0);
transform: translate3d(0, 10%, 0);
}
}
#-webkit-keyframes slideInUp
{
from
{
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to
{
-webkit-transform: translate3d(0, 10%, 0);
transform: translate3d(0, 10%, 0);
}
}
#-webkit-keyframes slideInUpChild
{
from
{
bottom: 0;
}
to
{
bottom: calc(100% - 100px);
}
}
#keyframes slideInUpChild
{
from
{
bottom: 0;
}
to
{
bottom: calc(100% - 100px);
}
}
You can achieve this by doing the following changes:
Set initial opacity of the element that contains the image as 0 because it needs to fade-in later.
To make sure that the foreground image fades-in and moves up a few seconds after background image has appeared and taken its position, add a delay that is more than animation-duration of the background image. Here, I have set it as 2s. (I have also increased animation-duration of the foreground image to make the effect more visible but that is optional).
Within the keyframes setting for the foreground image, make the initial state as opacity: 0 and bottom: 150px (this is equal to the height of the image).
Since there are 3 stages of animation for the foreground image (that is, the fade-in, the move and the fade-out), set the splits as 33%, 66% and 100%.
At 33% change its opacity alone to 1 while bottom position remains the same. This produces the fade-in effect.
At 66% retain the opacity as 1 but change the bottom position as required. This means that the image moves-up while still being visible.
At 100%, retain the bottom position as-is but change the opacity to 0. This makes it fade-out.
Modified CSS:
.slideInUpChild {
opacity: 0;
animation-name: slideInUpChild;
animation-duration: 4s;
animation-delay: 2s;
}
#keyframes slideInUpChild {
0% {
opacity: 0;
bottom: 150px;
}
33% {
opacity: 1;
bottom: 150px;
}
66% {
opacity: 1;
bottom: calc(100% - 100px);
}
100% {
opacity: 0;
bottom: calc(100% - 100px);
}
}
#a {
width: 100%;
height: 600px;
margin: 0 0 0 0;
padding: 0 0 0 0;
position: relative;
background-image: url(http://webneel.com/wallpaper/sites/default/files/images/08-2013/11-sea-beach-sand-wallpaper.jpg);
overflow: hidden;
}
#b {
width: 100%;
height: 10px;
margin: 0 0 0 0;
padding: 0 0 0 0;
position: absolute;
bottom: 0;
}
.animated {
animation-duration: 1s;
}
.slideInUp {
animation-name: slideInUp;
animation-duration: 1s;
}
.slideInUpChild {
opacity: 0;
animation-name: slideInUpChild;
animation-duration: 4s;
animation-delay: 2s;
}
#keyframes slideInUp {
from {
transform: translate3d(0, 100%, 0);
}
to {
transform: translate3d(0, 0%, 0);
}
}
#keyframes slideInUpChild {
0% {
opacity: 0;
bottom: 150px;
}
33% {
opacity: 1;
bottom: 150px;
}
66% {
opacity: 1;
bottom: calc(100% - 100px);
}
100% {
opacity: 0;
bottom: calc(100% - 100px);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div id="a" class="animated slideInUp">
<div id="b" class="animated slideInUpChild">
<img src="https://cdn3.iconfinder.com/data/icons/black-easy/512/535106-user_512x512.png" width="150px" alt="" />
</div>
</div>
Looking to build something like this - a spin the wheel - using only HTML and CSS, without Javascript
http://tpstatic.com/_sotc/sites/default/files/1010/source/roulettewheel.html
http://www.dougtesting.net/winwheel
Looking for some references or even to see if it can be done.
This is using the Hover effect of spinning. Since css doesn't have event handlers, you can't add/remove classes. However, you can add hover effects:
div {
height: 100px;
width: 100px;
border-radius: 50%;
background: gray;
margin: 0 auto;
text-align: center;
}
div:hover {
-webkit-animation: spin 0.8s infinite linear;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
Hover to see effect: <div>Spin</div>
If you could use a tiny bit of javascript, you could do something like this:
$('div').click(function(){
$(this).toggleClass("thisIsAdded");
});
div {
height: 100px;
width: 100px;
border-radius: 50%;
background: gray;
margin: 0 auto;
text-align: center;
}
.thisIsAdded {
-webkit-animation: spin 0.8s infinite linear;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Click to see:<div>spin</div>
Note:
The script here is purely toggling the class 'thisIsAdded'.
As Justinas pointed out We cant fire css style on click event. You need javascript for that. However you can use CSS animation to achieve the spin effect but only with pseudo-selectors.
below is a sample spin effect using only CSS
<style type="text/css">
.content
{
float:left;cursor:pointer;
}
.content::after
{
content:'>';float:right;margin:0 0 0 10px;
-moz-transition:0.5s all;-webkit-transition:0.5s all;
}
.content:hover::after
{
-moz-transform:rotate(90deg);-webkit-transform:rotate(90deg);
}
</style>
<body>
<div class="content">Sample</div>
</body>
Here you go.. Fiddle
CSS:
.circle {
border-radius: 50%;
position: absolute;
top: 10%;
left: 10%;
width: 120px;
height: 120px;
-webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite;
animation:spin 4s linear infinite;
background: repeating-linear-gradient(
45deg,
#606dbc,
#606dbc 10px,
#465298 10px,
#465298 20px
);
}
#-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
#-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
#keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }