Im trying to make divs move up infinity loop, and i'm struggle with the keyframes settings.
Can anyone help me figure out where I'm wrong and correct my mistake, I'm sure it's something so simple I just did not notice it.
Thank you very much.
#container {
color:#999;
text-transform: uppercase;
font-size:60px;
font-weight:bold;
padding-top:200px;
position:fixed;
width:100%;
bottom:45%;
display:block;
}
#flip {
height:100px;
overflow:hidden;
}
#flip > div > div {
color:#fff;
padding:10px 12px 10px 12px;
height:65px;
margin-bottom:45px;
display:inline-block;
}
#flip div:first-child {
animation: show 5s linear infinite;
}
#flip div div {
background:#42c58a;
}
#flip div:first-child div {
background:#4ec7f3;
}
#flip div:last-child div {
background:#DC143C;
}
#keyframes show {
0% {transform: translateY(0);}
50% {transform: translateY(50%);}
100% {transform: translateY(100%);}
}
<div id=container>
ENDLESS
<div id=flip>
<div><div>SMOOTHIES</div></div>
<div><div>MILKSHAKES</div></div>
<div><div>FRUIT SHAKES</div></div>
<div><div>COCTAILS</div></div>
<div><div>FRUIT SHAKES</div></div>
</div>
OPTIONS!
</div>
You're animating the full view port, #flip.
Instead you can wrap all the divs in a container, #filp-container, and animate it.
Here is the full edited code with a comment for each change:
#container {
color:#999;
text-transform: uppercase;
font-size:60px;
font-weight:bold;
padding-top:200px;
position:fixed;
width:100%;
bottom:45%;
display:block;
}
#flip {
height:100px;
overflow:hidden;
}
#flip-container div {
color:#fff;
padding:10px 12px 10px 12px;
height:65px;
margin-bottom:45px;
/* this will break the aliging of divs */
/* display:inline-block; */
}
/* we are targeting the container */
#flip-container {
animation: show 5s linear infinite;
}
#flip div div {
background:#42c58a;
}
#flip div:first-child div {
background:#4ec7f3;
}
#flip div:last-child div {
background:#DC143C;
}
#keyframes show {
0% {transform: translateY(0);}
/* 50% is unnecessay */
/* 50% {transform: translateY(50%);} */
/* to animate to upward use -100% */
100% {transform: translateY(-100%);}
}
<div id=container>
ENDLESS
<div id=flip>
<!-- adding a container around divs and animating it instead of the view port -->
<div id="flip-container">
<!-- removed unnecessary surrounding divs -->
<div>SMOOTHIES</div>
<div>MILKSHAKES</div>
<div>FRUIT SHAKES</div>
<div>COCTAILS</div>
<div>FRUIT SHAKES</div>
</div>
</div>
OPTIONS!
</div>
Related
If I wanted to Change the width of an element twice and animate that. For example:
box{
height:100px;
width:100px;
}
.box:hover{
width:300px;
width:200px;
}
I think you need keyframes animation. It should works properly in your case.
like this
#keyframes box-size {
0%, 100% {
width: 100px;
}
50% {
width: 300px;
}
}
.box{
height:100px;
width:100px;
background: pink;
}
.box:hover{
animation: box-size 2s;
}
<div class="box"></div>
If you use animation effect before mix-blend-mode property you will not get mix blend mode.
Once you remove the animation class or disable animation, then mix-blend-mode will work.
What is the problem? I spent hours to solve just this simple thing. Please, help
.box {
background-color:yellow;
overflow:hidden;
border-radius:10px;
}
.box img{ mix-blend-mode:multiply}
.animate{
border:1px solid red;
width:30px; height:30px;
animation: spin 2s infinite linear;
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(1turn); }
}
<div class="animate">123</div>
<div class="box">
<img src="https://placeimg.com/400/200/animals" alt="">
</div>
mix blend should take effect anyway
In the old times, adding a transform translateZ(0px) used to solve a lot of problems.
At least in my Chrome, seems to still be the case:
.box {
background-color:yellow;
overflow:hidden;
border-radius:10px;
transform: translateZ(0px); /* added */
}
.box img{ mix-blend-mode:multiply}
.animate{
border:1px solid red;
width:30px; height:30px;
animation: spin 2s infinite linear;
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(1turn); }
}
<div class="animate">123</div>
<div class="box">
<img src="https://placeimg.com/400/200/animals" alt="">
</div>
Adding mix-blend-mode to the parent element also, solves the issue.
.box {
background-color:yellow;
overflow:hidden;
border-radius:10px;
mix-blend-mode:multiply;
}
.box img{ mix-blend-mode:multiply;}
.animate{
border:1px solid red;
border-radius: 1rem;
width:2rem;
height:2rem;
animation: spin 2s infinite linear;
display:flex;
align-items: space-around;
align-content: stretch;
justify-content: space-around;
}
#keyframes spin {
0% { transform: rotate(0deg); background-color: aqua; }
50% { background-color: yellow; }
100% { transform: rotate(1turn); background-color: aqua; }
}
<div class="animate">•</div>
<div class="box">
<img src="https://placeimg.com/400/200/animals" alt="">
</div>
In this problem, animate's stack order is between box and img because animate use keyframe.I think keyframe change animate's stack order.So,Img cannot blend in box.We can change element's stack order by using z-index.
Solution is img must within box.We have two options.Results will be different where you use z-index.
First option, we can change animate's stack order in animate class.
`
.animate{
position:relative;
z-index:2;
}
`
Result - animate will be front of box with img.
Second option, we can change box's stack order in box class.
`
.box{
position:relative;
z-index:2;
}
`
Result - box with img will be front of animate.
.box {
background-color:yellow;
overflow:hidden;
border-radius:10px;
}
.box img{ mix-blend-mode:multiply}
.animate{
border:1px solid red;
width:30px; height:30px;
position:relative;
z-index:2;
animation: spin 2s infinite linear;
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(1turn); }
}
<div class="animate">123</div>
<div class="box">
<img src="https://placeimg.com/400/200/animals" alt="">
</div>
I try to animate a pseudo element width css3. Everything is ok. But on Firefox (43.0.3) at the end of the animation the font flickers:
div {
width:500px;
height:500px;
color:red;
font-size:100px;
background:black;
transform:matrix(1.0001,0.00,0.00,1.0001,0,0);
}
div:before {
content:"test";
font-size:100px;
color:white;
margin:0 0 0 200px;
display:block;
animation:test 2s ease-in-out 1s both;
transform:matrix(1.0001,0.00,0.00,1.0001,0,0);
}
#keyframes test {
0% {
transform:matrix(1.0001,0.00,0.00,1.0001,0,0);
}
50% {
transform:matrix(1.50,0.00,0.00,1.50,0,0);
}
100% {
transform:matrix(1.0001,0.00,0.00,1.0001,0,0);
}
}
<div></div>
[Edit] I didnt get the point how to link to jsfiddle. so heres the link:
jsfiddle.net SLASH focgzeye
Anyone could help?
Try to add line-height same as font-size:
line-height:100px;
Tested on Firefox 43.0.1 but with the same flicker problem.
Here the jsfiddle update.
I have a div with an inner span with text. This inside span should be centered vertically and horizontally all the time:
http://jsfiddle.net/QW4Wk/
<div>
<span>Text aligned center</span>
</div>
The div has a transition when the mouse is over, which changes its width and height.
div{
width:200px;
height:200px;
background:black;
position:relative;
-webkit-transition:width 10s,height 10s;
}
span {
position:absolute;
color:white;
bottom:0;
right:0;
}
div:hover{
width:250px;
height:250px;
}
However in Chrome (at least) the text looks choppy while the transition is running. I guess this is because the transition goes 1 by 1px and therefor the "center style" has to go back and forward 1px.
Is there someway to fix this to look smoother, something like subpixel?
Thanks.
try this for absolute centering the text..
span {
margin: auto;
color:white;
text-align:center;
height:10px;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
and of course lessen your transition speed.
Apply a different change to the span. a transform can be subpixel
div{
width:200px;
height:200px;
background:black;
position:relative;
-webkit-transition:width 10s,height 10s;
}
span {
position:absolute;
color:white;
top:75px;
left:50px;
width: 100px;
transition: -webkit-transform 10s;
-webkit-transform: translate(0px, 0px);
}
div:hover{
width:250px;
height:250px;
}
div:hover span {
-webkit-transform: perspective(999px) translate(25px, 25px);
}
fiddle
I am trying to make css3 slider when i set -moz- prefix for image sliding slider even not work in chrome let alone Mozilla Firefox. but =webkit- prefix is working good in Chrome if i do not use -moz prefix with -webkit. even i declare caption animation. Caption animation is not working.
just have look on my code : http://codepen.io/faeshaan/pen/pefwq
After adding in the keyframe definitions and css properties for mozilla (basically what #Ilan Biala said re: css markup) the animation still didn't work for me on OSX Firefox v22.
Adding an initial:
left: 0px;
Made the animation start working. Seems firefox didn't like animating left unless it was first explicitly defined in the css class.
I found a few issues looking at you code:
syntax for keyframes should be #keframes slide{} not #keyframes 'slide' {}
the slide animation was missing a closing }
added an initial left:0; position to .container ul as dc5 suggested
added a specific height of 200px to .container to make the heading animation look a little cleaner.
This will work as is in Firefox v22, but you will still need to add browser prefixes for full support.
Working Example
.container {
width:200px;
height:200px;
margin:0px auto;
overflow:hidden;
}
.container ul {
width:1000px;
list-style:none;
position:relative;
left:0;
animation: slide 20s infinite;
}
ul, li {
padding:0px;
margin:0px;
}
.container ul li {
position:relative;
left:0px;
float:left;
}
.container h5 {
background:rgba(0, 0, 0, 0.5);
position:absolute;
bottom:4px;
width:100%;
padding:5px;
color:#fff;
text-align:center;
margin-bottom:0px;
animation: headings 4s infinite;
}
#keyframes slide {
10% {
left:0px;
}
15%, 30% {
left:-200px;
}
35%, 50% {
left:-400px;
}
55%, 70% {
left:-600px;
}
75%, 90% {
left:-800px;
}
}
#keyframes headings {
10% {
margin-bottom:4px;
}
25%, 50% {
margin-bottom:-150px;
}
}
I rearranged your code to put the keyframe animation definitions below the properties that are using them. Also, you only had the -webkit-animation: ; declaration, so I added the other declarations for mozilla, microsoft, opera, and W3C compliant browsers.
I also combined the animation-iteration-count: ; into the animation: ; declaration because it saves a little text in the file.
So now instead of what you had before:
.container h5 {
background:rgba(0,0,0,0.5);
position:absolute;
bottom:4px;
width:100%;
padding:5px;
color:#fff;
text-align:center;
margin-bottom:0px;
-webkit-animation: headings 20s;
}
#-webkit-keyframes headings {
10% {
margin-bottom:4px;
}
15%,30% {
margin-bottom:-200px;
}
}
It looks like this:
.container h5 {
background:rgba(0,0,0,0.5);
position:absolute;
bottom:4px;
width:100%;
padding:5px;
color:#fff;
text-align:center;
margin-bottom:0px;
-webkit-animation: headings 20s;
-moz-animation: headings 20s;
-ms-animation: headings 20s;
-o-animation: headings 20s;
animation: headings 20s;
}
And I added the corresponding keyframe definitions.
The final pen is here.