I'm playing around with CSS animation, and I was wondering if there's a way to make a vertical line (with certain height) to grow in length automatically and turn to left and add an image at the end when the page loads. I was able to draw vertical line but how to turn it to left and add image.
https://jsfiddle.net/29303g27/3/
#cool
{
width:2px;
margin-left:10%;
background-color:#431;
margin-top:35%;
animation:grow 3s forwards;
position:relative;
}
#keyframes grow
{
0% {
height: 0px;
bottom:0;
}
100%{
height: 200px;
bottom:200px;
}
}
<div id=cool>
</div>
By using div inner div
#cool2{
height:0px;
width:1px;
border-bottom:2px solid #000;
-webkit-animation: increase 3s;
-moz-animation: increase 3s;
-o-animation: increase 3s;
animation: increase 3s;
animation-fill-mode: forwards;
margin-left:10%;
margin-top:0px;
animation-delay:5s;
-webkit-animation-delay:3s;
}
#keyframes increase {
100% {
width: 200px;
}
}
.image
{
width:0px;
height:200px;
left:2px;
top:2px;
-webkit-animation: fade 3s;
-moz-animation: fade 3s;
-o-animation: fade 3s;
animation: fade 3s;
animation-fill-mode: forwards;
margin-left:10%;
margin-top:0px;
animation-delay:6s;
-webkit-animation-delay:6s;
position:absolute;}
#keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 1;
width:200px;
}
}
#cool
{
width:2px;
margin-left:10%;
background-color:#431;
margin-top:35%;
animation:grow 3s forwards;
position:relative;
}
#keyframes grow
{
0% {
height: 0px;
bottom:0;
}
100%{
height: 200px;
bottom:200px;
}
}
<div id=cool>
<div id=cool2>
<img class='image' src='https://www.google.co.in/logos/doodles/2017/sitara-devis-97th-birthday-6469056130449408.5-l.png'>
</div>
</div>
and Check this 2nd way using :after Element
#cool:after{
height:0px;
width:1px;
border-bottom:2px solid #000;
-webkit-animation: increase 3s;
-moz-animation: increase 3s;
-o-animation: increase 3s;
animation: increase 3s;
animation-fill-mode: forwards;
margin-left:10%;
margin-top:0px;
animation-delay:5s;
-webkit-animation-delay:3s;
position:absolute;
content:'';
}
#keyframes increase {
100% {
width: 200px;
}
}
.image
{
width:0px;
height:200px;
left:2px;
top:2px;
-webkit-animation: fade 3s;
-moz-animation: fade 3s;
-o-animation: fade 3s;
animation: fade 3s;
animation-fill-mode: forwards;
margin-left:10%;
margin-top:0px;
animation-delay:6s;
-webkit-animation-delay:6s;
position:absolute;}
#keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 1;
width:200px;
}
}
#cool
{
width:2px;
margin-left:10%;
background-color:#431;
margin-top:35%;
animation:grow 3s forwards;
position:relative;
}
#keyframes grow
{
0% {
height: 0px;
bottom:0;
}
100%{
height: 200px;
bottom:200px;
}
}
<div id=cool>
<img class='image' src='https://www.google.co.in/logos/doodles/2017/sitara-devis-97th-birthday-6469056130449408.5-l.png'>
</div>
It can be done in many ways. Example
In example I use wrapper element and place line element inside. In this way, line element can use percentage value which relate to wrapper element. It means we don't need to fix height or width just let it grows by image.
<div class='wrapper'>
<img class='image' src='https://images.unsplash.com/photo-1485963631004-f2f00b1d6606?auto=format&fit=crop&w=360&h=180&q=60'>
<div class='line'></div>
</div>
and now animation will be
#keyframes show-up {
0% {
height: 0;
}
50% {
left: 0;
height: 100%;
}
100% {
left: 100%;
height: 100%;
}
}
Related
I want to have a div, with a word inside. This word should appear with animation when the div is hovered over. This is animating and behaving the way I want, EXCEPT... the word "hello" is visible when the page loads. I want it to be hidden, and then animate into view. What do I need to fix?
#test{
border: 1px solid #000;
}
#hello {
animation-name: hello;
animation-duration: 0.5s;
animation-fill-mode: backwards;
animation-play-state: paused;
}
#hello:hover {
animation-fill-mode: forwards;
animation-play-state: running;
visibility: visible;
}
#keyframes hello {
0% {visibility:(hidden);transform:scale(0.5); opacity:(0.0);}
1% {visibility:(visible);}
50% {transform:scale(1.2); opacity:(0.5);}
100% {transform:scale(1.0); opacity:(1.0);}
}
<div id="test">
<div id="hello">
Hello!
</div>
</div>
You need to simply remove () from the values of properties as it make them invalid. Also it's better to change the opacity in the 1% of the animation to be able to see the scale effect.
You may also remove the visiblity property from the CSS as it's useless since you are using opacity
#test {
border: 1px solid #000;
background:#fff;
overflow:hidden; /* added this to avoid the scroll to appear and disappear*/
}
#hello {
animation-name: hello;
animation-duration: 0.5s;
animation-fill-mode: backwards;
animation-play-state: paused;
}
#test:hover #hello {
animation-fill-mode: forwards;
animation-play-state: running;
/*visibility: visible; can be removed*/
}
#keyframes hello {
0% {
/*visibility: hidden; can be removed*/
transform: scale(0.5);
opacity: 0;
}
1% {
/*visibility: visible; can be removed*/
opacity:0.3;
}
50% {
transform: scale(1.2);
opacity:0.5;
}
100% {
transform: scale(1.0);
opacity:1.0;
}
}
<div id="test">
<div id="hello">
Hello!
</div>
</div>
I want to an object move out and in screen(slide in left to right and slide out right to left).
I use this CSS:
#-webkit-keyframes slideInSmooth {
0% {
-webkit-transform: translate3d(-100%,0,0);
}
100% {
-webkit-transform: translate3d(0,0,0);
}
}
#-webkit-keyframes slideOutSmooth {
0% {
-webkit-transform: translate3d(0,0,0);
}
100% {
-webkit-transform: translate3d(-100%,0,0);
}
}
.tabs {
-webkit-animation: slideInSmooth ease-in 250ms;
animation: slideInSmooth ease-in 250ms;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
-webkit-animation-duration: 250ms;
animation-duration: 250ms;
}
.tabs-item-hide > .tabs{
-webkit-animation: slideOutSmooth ease-in 250ms;
animation: slideOutSmooth ease-in 250ms;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
-webkit-animation-duration: 250ms;
animation-duration: 250ms;
}
My Html look like this:
<div id="div1" class="">
<div class="tabs">
</div>
</div>
class tabs-item-hide will be add in div1 by an event and after that item
hide.
class tabs-item-hide will be remove in div1 by an event if want to show
item
The code work fine when object show, it slide from left to right perfect.
But when object hide it does nothing!
Please help me correct my css to have object move from right to left out of screen.
Thanks!
I hope I understood you correctly, but I guess that should work for you.
.tabs-item-hide {
width:100%;
overflow:hidden;
position:relative;
height:50px;
}
#-webkit-keyframes slideInSmooth {
0% { left:0; }
90% { left:100%; }
90.0001% { left:-50px; }
100% { left:0; }
}
#keyframes slideInSmooth {
0% { left:0; }
90% { left:100%; }
90.0001% { left:-50px; }
100% { left:0; }
}
.tabs {
-webkit-animation: slideInSmooth 2.5s forwards;
animation: slideInSmooth 2.5s forwards;
position:absolute;
width:50px;
height:50px;
background:#ffa500;
}
<div class="tabs-item-hide">
<div class="tabs"></div>
</div>
In the slideshow shown below, there are two images available. Once clicking on a button for the second image after first opening my page, there is a sudden jump to that image with no 5 second transition as expected. Also when doing this, I notice that #slideshowimage-2 is shown in the url (doing this offline) after clicking the button for that image. Here's the code below:
CSS:
.slideshowcontainer {
width:800px;
height:400px;
margin-left:auto;
margin-right:auto;
margin-top:0px;
text-align:center;
overflow:hidden;
position:relative;
top:30px;
border-style:solid;
border-width:10px;
border-color:white;
border-radius:15px;
}
.imagecontainer {
width:1800px;
height:400px;
clear: both;
position:relative;
-webkit-transition:left 3s;
-moz-transition:left 3s;
-o-transition:left 3s;
-ms-transition:left 3s;
transition:left 3s;
animation:scroller 16s infinite;
}
#keyframes scroller {
0% {transform:translateX(0);}
31.25% {transform:translateX(0);}
50% {transform:translateX(-800px);}
81.25% {transform:translateX(-800px);}
100% {transform:translateX(0);}
}
.slideshowimage {
float:left;
margin:0px;
padding:0px;
position:relative;
}
#keyframes change {
0% {
transform: translateX(-800px);
}
100% {
transform: translateX(0);
animation: scroller 16s infinite;
}
}
#keyframes change2 {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-800px);
animation: scroller2 16s infinite;
}
}
#slideshowimage-1:target ~ .imagecontainer {
animation: none;
transform: translateX(0px);
animation: change 3s forwards;
}
#slideshowimage-2:target ~ .imagecontainer {
animation: none;
transform: translateX(-800px);
animation: change2 3s forwards;
}
.buttoncontainer {
position:relative;
top:-20px;
}
.button {
display:inline-block;
height:10px;
width:10px;
border-radius:10px;
background-color:darkgray;
-webkit-transition:background-color 0.25s;
-moz-transition:background-color 0.25s;
-o-transition:background-color 0.25s;
-ms-transition:background-color 0.25s;
transition:background-color 0.25s;
}
.button:hover {
background-color:gray;
}
HTML:
<div class="slideshowcontainer">
<span id="slideshowimage-1"></span>
<span id="slideshowimage-2"></span>
<span id="slideshowimage-3"></span>
<div class="imagecontainer">
<img src="WebServiceSlide.png" class="slideshowimage" style="width:800px;height:400px;">
<img src="es-flag.png" class="slideshowimage" style="width:800px;height:400px;">
</div>
<div class="buttoncontainer">
</div>
</div>
How could I make it so that the transition set upon clicking a button occurs on the first click? Many thanks in advance.
Reason:-
Because the left and translateX both are different. If you apply left:-800px when slide is at translateX(-800px) (2nd slide) then animation will continue at the 2nd part of slideshow. Thats why you are seeing a blank white space(when translateX(-800px) accors when it is already left:-800px).
Solution:-
You either have to use translateX or left. use the same in all the places
Part of code that solved the problem:-
#keyframes change {
0% {
transform: translateX(-800px);
}
100% {
transform: translateX(0);
animation: scroller 16s infinite;
}
}
#keyframes change2 {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-800px);
animation: scroller2 16s infinite;
}
}
#slideshowimage-1:target ~ .imagecontainer {
animation: none;
transform: translateX(0px);
animation: change 3s forwards;
}
#slideshowimage-2:target ~ .imagecontainer {
animation: none;
transform: translateX(-800px);
animation: change2 3s forwards;
}
Explanation:-
This code doesn't do translateX manually. Instead it uses animation to scoll single time by animation: change 3s forwards;
Drawback:-
Once we click on the slide selection button the animation stops. I have even tried it to solve by adding animation in the change keyframes animate end section. But unfortunately it didn't work. So I would suggest an alternate method to overcome the drawback as follows
To overcome the drawback I have added a play button which
will replay the slideshow animation which got paused by the slide
button. (Once we click on play button it takes a little time to slide
as we have given 16s in animation)
DEMO:-
.slideshowcontainer {
width: 800px;
height: 400px;
margin-left: auto;
margin-right: auto;
margin-top: 0px;
text-align: center;
overflow: hidden;
position: relative;
top: 30px;
border-style: solid;
border-width: 10px;
border-color: white;
border-radius: 15px;
}
.imagecontainer {
width: 1800px;
height: 400px;
clear: both;
position: relative;
-webkit-transition: all 3s;
-moz-transition: all 3s;
-o-transition: all 3s;
-ms-transition: all 3s;
transition: all 3s;
transform: translateX(0px);
animation: scroller 16s infinite;
}
#keyframes scroller {
0% {
transform: translateX(0);
}
31.25% {
transform: translateX(0);
}
50% {
transform: translateX(-800px);
}
81.25% {
transform: translateX(-800px);
}
100% {
transform: translateX(0);
}
}
#keyframes scroller2 {
0% {
transform: translateX(-800px);
}
31.25% {
transform: translateX(-800px);
}
50% {
transform: translateX(0);
}
81.25% {
transform: translateX(0);
}
100% {
transform: translateX(-800px);
}
}
#keyframes change {
0% {
transform: translateX(-800px);
}
100% {
transform: translateX(0);
animation: scroller 16s infinite;
}
}
#keyframes change2 {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-800px);
animation: scroller2 16s infinite;
}
}
.slideshowimage {
float: left;
margin: 0px;
padding: 0px;
position: relative;
}
#slideshowimage-1:target ~ .imagecontainer {
animation: none;
transform: translateX(0px);
animation: change 3s forwards;
}
#slideshowimage-2:target ~ .imagecontainer {
animation: none;
transform: translateX(-800px);
animation: change2 3s forwards;
}
#slideshowimage-3:target ~ .imagecontainer {
transform: translateX(0);
animation: scroller 16s infinite;
}
.buttoncontainer {
position: relative;
top: -20px;
}
.button {
display: inline-block;
height: 10px;
width: 10px;
border-radius: 10px;
background-color: darkgray;
-webkit-transition: background-color 0.25s;
-moz-transition: background-color 0.25s;
-o-transition: background-color 0.25s;
-ms-transition: background-color 0.25s;
transition: background-color 0.25s;
}
.button:hover {
background-color: gray;
}
.buttonplay:after {
height: 0;
width: 0;
top: 0;
margin-left: 10px;
position: absolute;
content: ' ';
border-left: solid 13px darkgray;
border-top: solid 8px transparent;
border-bottom: solid 8px transparent;
}
<div class="slideshowcontainer">
<span id="slideshowimage-1"></span>
<span id="slideshowimage-2"></span>
<span id="slideshowimage-3"></span>
<div class="imagecontainer">
<img src="https://placehold.it/800x400" class="slideshowimage" style="width:800px;height:400px;">
<img src="https://placehold.it/900x450" class="slideshowimage" style="width:800px;height:400px;">
</div>
<div class="buttoncontainer">
</div>
</div>
I am new to CSS and still don't get a lot of stuff! Using only CSS animations I have to create a spinning animation over a roulette.I have to create a sphere and as a background use a roulette img. My question is how can I change the position of the sphere every 10% of the animation, so it can make a full circle around the roulette.
This is the img I am using as a background: http://www.casinoanswers.com/wp-content/uploads/2010/03/american-roulette-wheel.gif
HTML:
<div id="roulette">
<figure class="circle"></figure>
</div>
CSS:
#roulette{
background-image: url("american-roulette-wheel.gif");
width:395px;
height:400px;
margin:0;
}
.circle {
position:fixed;
top:84px;
left:190px;
border-radius: 50%;
height: 30px;
width: 30px;
margin:0;
background: radial-gradient(circle at 10px 10px, #5cabff, #000);
}
Thank you!
By placing your ball/circle image inside a container div and rotating that div, you can create the illusion of the ball traveling around the background. You will have to play with positioning to get it exact, and it might be cool to rotate the ball as well as the container div.
<div id="roulette">
<div class="circleContainer">
<figure class="circle"></figure>
</div>
</div>
#roulette{
background-image: url(http://www.casinoanswers.com/wp-content/uploads/2010/03/american-roulette-wheel.gif);
width:395px;
height:400px;
margin:0;
}
.circle {
border-radius: 50%;
height: 30px;
width: 30px;
margin:0;
background: radial-gradient(circle at 10px 10px, #5cabff, #000);
}
#-webkit-keyframes spinnerRotate
{
from{-webkit-transform:rotate(0deg);}
to{-webkit-transform:rotate(360deg);}
}
#-moz-keyframes spinnerRotate
{
from{-moz-transform:rotate(0deg);}
to{-moz-transform:rotate(360deg);}
}
#-ms-keyframes spinnerRotate
{
from{-ms-transform:rotate(0deg);}
to{-ms-transform:rotate(360deg);}
}
.circleContainer{
height: 250px;
top: 80px;
position: fixed;
left: 190px;
-webkit-animation-name: spinnerRotate;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: spinnerRotate;
-moz-animation-duration: 5s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: spinnerRotate;
-ms-animation-duration: 5s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
}
https://jsfiddle.net/2gat1m5y/1/
I would like to simulate a loading effect, so the opacity of the image is changing gradually.
body {
background-color: #aaa;
padding: 10px;
}
#progressbar {
width: 269px;
height: 269px;
background-color: #eee;
clear: both;
}
#progress {
background: #fff; /*-- Color of the bar --*/
height: 269px;
width: 0%;
max-width: 269px;
float: left;
-webkit-animation: progress 2s 1 forwards;
-moz-animation: progress 2s 1 forwards;
-ms-animation: progress 2s 1 forwards;
animation: progress 2s 1 forwards;
}
#pbaranim {
height: 269px;
width: 269px;
overflow: hidden;
background: url("http://i57.tinypic.com/acyid2.jpg");
-moz-opacity: 0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=55);
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=55);
filter: alpha(opacity=55);
}
#-webkit-keyframes progress {
from { }
to { width: 100% }
}
#-moz-keyframes progress {
from { }
to { width: 100% }
}
#-ms-keyframes progress {
from { }
to { width: 100% }
}
#keyframes progress {
from { }
to { width: 100% }
}
<div id="progressbar"><div id="progress" ><div id="pbaranim"></div></div></div>
In my example, the Div is over the image.
I need the image opacity to become clearer, so the inverse of what I have
Image should appear from 0 to 100%
Makes sense?
thanks for any help
You can achieve the effect with the following code:
CSS
#progressBar {
position:relative;
}
#progressImg {
width:391px;
}
#opacObj {
-webkit-animation:opacAnimation 4s 1 cubic-bezier(0, 1.09, .66, .96);
-webkit-animation-fill-mode: forwards;
-moz-animation:opacAnimation 4s 1 cubic-bezier(0, 1.09, .66, .96);
-moz-animation-fill-mode: forwards;
-o-animation:opacAnimation 4s 1 cubic-bezier(0, 1.09, .66, .96);
-o-animation-fill-mode: forwards;
animation:opacAnimation 4s 1 cubic-bezier(0, 1.09, .66, .96);
animation-fill-mode: forwards;
width:391px;
height:364px;
background:#fff;
position:absolute;
top:0;
left:0;
}
#-webkit-keyframes opacAnimation {
0% {
opacity:0.8;
left:0;
}
100% {
opacity:0.0;
left:391px;
}
}
#-moz-keyframes opacAnimation {
0% {
opacity:0.8;
left:0;
}
100% {
opacity:0.0;
left:391px;
}
}
#-o-keyframes opacAnimation {
0% {
opacity:0.8;
left:0;
}
100% {
opacity:0.0;
left:391px;
}
}
#keyframes opacAnimation {
0% {
opacity:0.8;
left:0;
}
100% {
opacity:0.0;
left:391px;
}
}
HTML
<div id="progressbar">
<img src="http://i57.tinypic.com/acyid2.jpg" border="0" id="progressImg">
<div id="opacObj"></div>
</div>
jsFiddle demo
Change the nesting hierarchy of your objects, namedly progress and pbaranim divs, as this
<div id="progressbar"><div id="pbaranim"><div id="progress" ></div></div></div>
You will progress from there on, by adding another image with the from color, and keep current image as the to color (from and to colors of animation) etc...