I'm trying to create a slide up/down or right/left animation, but I couldn't get it to work. How to hide the first div after some time with a sliding effect? how to play with display in animation
some help will be apreciated, this what I'm doing
<div id="div1">Fist div</div>
<div id="div2">Second div </div>
#div1{
animation: slideup 7s;
-moz-animation: slideup 7s;
-webkit-animation: slideup 7s;
-o-animation: slideup 7s;
}
#div2
{
position:relative;
}
#keyframes slideup
{
0% {top:0px;}
75% {top:0px;}
100% {top:-20px;}
}
#-moz-keyframes slideup
{
0% {top:0px;}
75% {top:0px;}
100% {top:-20px;}
}
#-webkit-keyframes slideup
{
0% {top:0px;}
75% {top:0px;}
100% {top:-20px;}
}
#-o-keyframes slideup
{
0% {top:0px;}
75% {top:0px;}
100% {top:-20px;}
}
No way to do this just with CSS and HTML. However it is possible to do with JavaScript. With JavaScript you can detect when the animation has ended using an Event Listener. Then you can remove or hide the div you want.
var div = document.getElementById("div1");
//add the event listener
div.addEventListener("animationend", function(event){
document.getElementById("div2").style.display = "none";
});
//you will need to explicitly add the class that contains the animation
div.classList.addClass("animate");
Change your CSS to be declared on the class .animate instead of on #div1. Also, be aware of browser prefixes. For more detail refer to this link.
Related
I'm trying to get some text to slide from the left to the center of the webpage using HTML and CSS animations. The goal is to have the first block of text slide into the center first, then after a 2 second delay, have the second block of text slide into the center. So that there will be a nice effect of the reader watching lines as they are written on the page.
Here is the HTML code:
/* .slide1 {
-webkit-animation : slideIn 2s forwards;
-moz-animation : slideIn 2s forwards;
animation : slideIn 2s forwards;
} */
.slide2 {
/* animation-delay: 2s; */
margin-top : -20px;
-webkit-animation : slideIn 2s forwards;
-moz-animation : slideIn 2s forwards;
animation : slideIn 2s forwards;
}
#-webkit-keyframes slideIn {
0% { transform: translateX(-900px); }
100% { transform: translateX(0); }
}
#-moz-keyframes slideIn {
0% { transform: translateX(-900px); }
100% { transform: translateX(0); }
}
#keyframes slideIn {
0% { transform: translateX(-900px); }
100% { transform: translateX(0); }
}
<h1 class="slide1">You want to go to the moon.<br></h1>
<h1 class="slide2">Weโre here to give you a shot.</h1>
So the trouble is, the animation is working for the second line, but not for the first line when you uncomment the class slide1 above.
The entire thing moves together, which is not what is supposed to happen. The point of having a delay for the animation in slide2 is meant so that after the first block of text finishes moving into the center, then the second block of text will start to move right.
It's confusing why this isn't working -
if you have any solutions to this, please share them!
you must first position your .slide1 and .slide2 off-screen
transform : translateX(-100vw);
...and contrary to what you imagine, the css commands must also respect an order and your delay command must be placed second after the global command of your translate
โ ๐ต very very bad :
animation-delay : 2s;
animation : 2s slideIn forwards;
( it make animation-delay : 0; )
๐ ๐ good :
animation : 2s slideIn forwards;
animation-delay : 2s;
.
otherwise you must respect the correct ordering of the arguments
animation : 2s 2s slideIn forwards;
but in my opinion the best way to write this - without repeating css:
.slide {
text-align : center;
transform : translateX(-100vw);
animation : 2s slideIn forwards;
}
.second {
margin-top : -.8em;
animation-delay : 2s;
}
#keyframes slideIn {
0% { transform : translateX(-100vw); }
100% { transform : translateX(0); }
}
<h1 class="slide">You want to go to the moon.</h1>
<h1 class="slide second">Weโre here to give you a shot.</h1>
also note the use of units, and the correct way to center your text whatever the width of the display (as you indicate in your question)
So I currently have an image that is rotating 360degs in an infinite loop. It has 8 different products in the image and instead of linking the entire image itself to one page, I was wondering if there was a way I could image map each product separately while the image still rotates 360degs.
I'm currently using a simple CSS3 image rotate as seen below:
.animation
{
-webkit-animation:spin 18s linear infinite;
-moz-animation:spin 18s linear infinite;
animation:spin 18s linear infinite;
}
#-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); } }
Anyone ever seen this implemented before?
This is really tough problem. I would not personally use image maps in that case, but some clickable divs with opacity:0 on your image.
If you do so, you can rotate them with your image, but changing transform-origin property, so the point of rotation would be the same.
This is the css that i have,
div {
background-image: url(some url);
width:100px;
height:100px;
background-size:cover;
}
.animate {
animation:changeSize 3s 1;
}
#keyframes changeSize {
0% {transform: scale(1);}
65% {transform: scale(1.2);}
100% {transform: scale(1.4);}
}
And with Jquery while clicking on a button i am just toggling the class animate to the div. But it seems not working. I am new to css3 animations and i dont know how to debug this. Any clues would be helpful for me in this context.
DEMO
Hi its working fine only on firefox and you has to add vendor prefix for webkit browser
#-webkit-keyframes
here it is
#keyframes changeSize {
0% {transform: scale(1);}
65% {transform: scale(1.2);}
100% {transform: scale(1.4);}
}
#-webkit-keyframes changeSize {
0% {transform: scale(1);}
65% {transform: scale(1.2);}
100% {transform: scale(1.4);}
}
check the fiddle
Fiddle
and add transition to the div you needed.
You may play with css3 animation fill property
.animate {
animation:changeSize 3s 1 forwards;
}
please find jsfiddle link http://jsfiddle.net/FLG4D/16/
here I have played with "backanimate" class as well so toggle back will be smooth as well
similar question Can't stop css animation disappearing after last key frame
Hope it helps!
I am trying to make a background fade-in swapping with another image, like fading in colors like :
animation: fading 35s infinite;
-webkit-animation: fading 35s infinite;
font-family:siteFont;
}
#keyframes fading {
width:100%;
0% {background-image:url (red;}
25% {background: yellow; }
50% {background: blue; }
75% {background: green;}
100% {background: red;}
}
or is there another method with css to do this ?
Try this: http://jsfiddle.net/myTerminal/U32gf/
I just kept on changing background-image.
Besides, the CSS that you have put here is broken badly.
I'm trying to create a graceful transition between the images within my photo gallery without using ":hover" or an once of Javascript. (I'm still open minded to HTML5)
The animation, this slideshow, should begin on page load, no user interaction needed. However my CSS isn't properly timed. Ideally, every 6 seconds, the current image begins to fade out just as the next image begins to fade in. The animation should loop infinitely after the last image.
I'm using a delay between the images in an attempt to stagger the animations, but the images overlap each other far too much. I seem to have misunderstood a number of things. My Css is below:
#imgContainer {
height: 205px;
position: relative;
width: 300px;
}
#imgContainer img {
-moz-animation-duration: 12s;
-moz-animation-iteration-count: infinite;
-moz-animation-name: FadeInOut;
-moz-animation-timing-function: ease-in-out;
left: 0;
position: absolute;
}
#imgContainer img:nth-of-type(1) {
-moz-animation-delay: 0s;
}
#imgContainer img:nth-of-type(2) {
-moz-animation-delay: 6s;
}
#imgContainer img:nth-of-type(3) {
-moz-animation-delay: 12s;
}
#-moz-keyframes FadeInOut {
0% {
opacity:0;
}
100% {
opacity:1;
}
}
I'm really new to css3, so any kind of assistance would be greatly appreciated.
Success!
I discovered if I apply an animation to each of my images within the slideshow, rather than being delayed, I could achieve the effect I desired. Basically the animations would run sequentially in an infinite loop, and rather than use a single keyframe, each has their own.
I wanted the slideshow to progress at 15s intervals. So to accomplish this I set the duration of the entire animation to 45s. The keyframes gradually adjust the opacity of the images based on the current time or frame within the animation. This is indicated by the "%." For example, from 2% to 32% of 45s, the keyframe for the first image will be 100% opaque. Between 32% and 34%, the first image will begin the transition from being opaque to completely transparent.
The difference between (34% of 45s) - (32% of 45s) equals the length of time to complete the transition. Increase this difference for a longer transition.
The keyframe for the second image does the same only its' transition doesn't begin until it reaches 33% of the 45s animation. (I chose to overlap them slightly for visual appeal). Again, I use the difference between 33% and 35% to keep the transition time short, rather than 0% and 35% which would've produced a much longer transition.
The third keyframe follows the same scheme for its image.
As you implement this, don't forget to change / add the appropriate vendor prefix for your browser and browser of your web audience.
/*Chrome/Safari: -webkit- \ FireFox +4: -moz- \ Opera: -o- \ IE9?: -ms- */
I hope this is helpful to anyone else who may be trying to do the same. If you like what you've read, please feel free to let me know as you vote using the up-arrow.
Thanks.
=)
#imgContainer img{
position:absolute;
left:0;
}
#image0 {
-moz-animation: 45s linear 0s normal none infinite myKeyFrameName0;
}
#image1 {
-moz-animation: 45s linear 0s normal none infinite myKeyFrameName1;
}
#image2 {
-moz-animation: 45s linear 0s normal none infinite myKeyFrameName2;
}
#-moz-keyframes myKeyFrameName0 {
0% {opacity: 0;}
2% {opacity: 1;}
32% {opacity: 1;}
34% {opacity: 0;}
100% {opacity: 0;}
}
#-moz-keyframes myKeyFrameNamee1 {
0% {opacity: 0;}
33% {opacity: 0;}
35% {opacity: 1;}
65% {opacity: 1;}
67% {opacity: 0;}
100% {opacity: 0;}
}
#-moz-keyframes myKeyFrameName2 {
0% {opacity: 0;}
66% {opacity: 0;}
68% {opacity: 1;}
98% {opacity: 1;}
100% {opacity: 0;}
}